home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / term-source.lha / ARexxCommands.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  84KB  |  4,661 lines

  1. /*
  2. **    ARexxCommands.c
  3. **
  4. **    ARexx interface command support routines
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* Cheapo shortcuts */
  17.  
  18. #define Args        Pkt->Array
  19. #define ResultCode    Pkt->Results
  20.  
  21.     /* ScanNodeFilter(UBYTE *Data,LONG Size,struct List *List,UBYTE Mask,UBYTE **DataPtr):
  22.      *
  23.      *    Scans a data buffer for matches with the names of the list nodes. It
  24.      *    will return the matching node name and place the address where the
  25.      *    matching node name was found in the input buffer in DataPtr. If nothing
  26.      *    is found, NULL will be returned.
  27.      */
  28.  
  29. STATIC STRPTR
  30. ScanNodeFilter(UBYTE *Data,LONG Size,struct List *List,UBYTE Mask,UBYTE **DataPtr)
  31. {
  32.     STRPTR Result;
  33.     UBYTE Char;
  34.  
  35.         /* This is where the result of the search will be placed. */
  36.  
  37.     Result = NULL;
  38.  
  39.         /* Run down the input string. */
  40.  
  41.     while(Size--)
  42.     {
  43.             /* Get the next character, promote it to upper case
  44.              * and strip off the high order bit if necessary.
  45.              */
  46.  
  47.         if(Char = ToUpper((*Data++) & Mask))
  48.         {
  49.             struct WaitNode *Node;
  50.             UBYTE MatchChar;
  51.  
  52.                 /* Try to find the nodes in which the next character of the
  53.                  * name matches the character we just picked from the string.
  54.                  */
  55.  
  56.             for(Node = (struct WaitNode *)List->lh_Head ; Node->Node.ln_Succ ; Node = (struct WaitNode *)Node->Node.ln_Succ)
  57.             {
  58.                     /* This is the next character to match in the node name. */
  59.  
  60.                 MatchChar = ToUpper(Node->Node.ln_Name[Node->Count]) & Mask;
  61.  
  62.                     /* If it doesn't match the character we just got,
  63.                      * restart from the beginning of the node name.
  64.                      */
  65.  
  66.                 if(Char != MatchChar)
  67.                 {
  68.                     Node->Count = 0;
  69.  
  70.                     MatchChar = ToUpper(Node->Node.ln_Name[0]) & Mask;
  71.                 }
  72.  
  73.                     /* Does the character match? */
  74.  
  75.                 if(Char == MatchChar)
  76.                 {
  77.                         /* Increase the number of matching characters. */
  78.  
  79.                     Node->Count++;
  80.  
  81.                         /* Does the entire name match? */
  82.  
  83.                     if(!Node->Node.ln_Name[Node->Count])
  84.                     {
  85.                             /* If there is a response string
  86.                              * attached, send it. Otherwise
  87.                              * remember the matching string.
  88.                              */
  89.  
  90.                         if(Node->ResponseLen)
  91.                             SerWriteVerbatim(Node->Response,Node->ResponseLen,FALSE);
  92.                         else
  93.                             Result = Node->Node.ln_Name;
  94.  
  95.                         Node->Count = 0;
  96.                     }
  97.                 }
  98.             }
  99.  
  100.                 /* If we got something, return now. */
  101.  
  102.             if(Result != NULL)
  103.             {
  104.                 *DataPtr = Data;
  105.  
  106.                 return(Result);
  107.             }
  108.         }
  109.     }
  110.  
  111.         /* Couldn't find anything. */
  112.  
  113.     return(NULL);
  114. }
  115.  
  116. STRPTR
  117. RexxWait(struct RexxPkt *Pkt)
  118. {
  119.     enum    {    ARG_WAIT_NOECHO,ARG_TIMEOUT,ARG_WAIT_TEXT };
  120.  
  121.     UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  122.     struct List LocalList,*MatchList;
  123.     struct WaitNode LocalWaitNode;
  124.     ULONG Signals;
  125.     STRPTR Result;
  126.     LONG Timeout;
  127.     UBYTE Mask;
  128.     BOOL Echo;
  129.     BOOL Done;
  130.  
  131.     if(!ReadRequest || !WriteRequest)
  132.     {
  133.         ResultCode[0] = RC_WARN;
  134.  
  135.         return(NULL);
  136.     }
  137.  
  138.     if(Args[ARG_WAIT_NOECHO])
  139.         Echo = FALSE;
  140.     else
  141.         Echo = TRUE;
  142.  
  143.     if(Args[ARG_WAIT_TEXT])
  144.     {
  145.         LONG Len;
  146.  
  147.         NewList(&LocalList);
  148.  
  149.         CopyMem(Args[ARG_WAIT_TEXT],LocalBuffer,sizeof(LocalBuffer) - 1);
  150.         LocalBuffer[sizeof(LocalBuffer) - 1] = 0;
  151.  
  152.         Len = TranslateString(LocalBuffer,LocalBuffer);
  153.         LocalBuffer[Len] = 0;
  154.  
  155.         memset(&LocalWaitNode,0,sizeof(struct WaitNode));
  156.  
  157.         LocalWaitNode.Node.ln_Name = LocalBuffer;
  158.  
  159.         AddTail(MatchList = &LocalList,(struct Node *)&LocalWaitNode);
  160.     }
  161.     else
  162.     {
  163.         if(!GenericListCount(GenericListTable[GLIST_WAIT]))
  164.         {
  165.             ResultCode[0] = RC_ERROR;
  166.             ResultCode[1] = TERMERROR_LIST_IS_ALREADY_EMPTY;
  167.  
  168.             return(NULL);
  169.         }
  170.         else
  171.         {
  172.             struct WaitNode *Node;
  173.  
  174.             MatchList = (struct List *)GenericListTable[GLIST_WAIT];
  175.  
  176.             LockGenericList((struct GenericList *)MatchList);
  177.  
  178.             for(Node = (struct WaitNode *)MatchList->lh_Head ; Node->Node.ln_Succ ; Node = (struct WaitNode *)Node->Node.ln_Succ)
  179.                 Node->Count = 0;
  180.         }
  181.     }
  182.  
  183.     if(Config->SerialConfig->StripBit8)
  184.         Mask = 0x7F;
  185.     else
  186.         Mask = 0xFF;
  187.  
  188.     if(Args[ARG_TIMEOUT])
  189.         Timeout = *(LONG *)Args[ARG_TIMEOUT];
  190.     else
  191.         Timeout = RexxTimeoutVal;
  192.  
  193.     if(Timeout)
  194.         StartTime(Timeout,0);
  195.  
  196.     Lock_xOFF();
  197.     Clear_xOFF();
  198.  
  199.     Result = NULL;
  200.     Done = FALSE;
  201.  
  202.     do
  203.     {
  204.         Signals = (*SerialWaitForData)(SIG_WINDOW | SIG_BREAK | SIG_TIMER);
  205.  
  206.         if(Signals & SIG_WINDOW)
  207.             while(RunJob(WindowJob));
  208.  
  209.         if(Signals & SIG_SERIAL)
  210.         {
  211.             ULONG Length;
  212.  
  213.             if(Length = (*SerialGetWaiting)())
  214.             {
  215.                 if(Length > SerialBufferSize / 2)
  216.                     Length = SerialBufferSize / 2;
  217.  
  218.                 if(Length > Config->SerialConfig->Quantum)
  219.                     Length = Config->SerialConfig->Quantum;
  220.  
  221.                 if(Length = (*SerialRead)(ReadBuffer,Length))
  222.                 {
  223.                     BytesIn += Length;
  224.  
  225.                     if(Translate_CR_LF)
  226.                         Length = (*Translate_CR_LF)(ReadBuffer,Length);
  227.  
  228.                     if(Length)
  229.                     {
  230.                         UBYTE *NewData;
  231.  
  232.                         if(Result = ScanNodeFilter(ReadBuffer,Length,MatchList,Mask,&NewData))
  233.                         {
  234.                             ULONG NewLength;
  235.  
  236.                             NewLength = (ULONG)NewData - (ULONG)ReadBuffer;
  237.  
  238.                             if(NewLength + strlen(Result) != Length)
  239.                             {
  240.                                 DataHold = NewData;
  241.                                 DataSize = Length - NewLength;
  242.  
  243.                                 UpdateSerialJob();
  244.                             }
  245.  
  246.                             Length = NewLength;
  247.  
  248.                             Done = TRUE;
  249.                         }
  250.  
  251.                         if(Echo && Length)
  252.                             ConProcess(ReadBuffer,Length);
  253.                     }
  254.                 }
  255.             }
  256.         }
  257.  
  258.         if(Signals & (SIG_BREAK | SIG_TIMER))
  259.         {
  260.             if(!Result)
  261.                 ResultCode[0] = RC_WARN;
  262.  
  263.             Done = TRUE;
  264.         }
  265.     }
  266.     while(!Done);
  267.  
  268.     if(MatchList == (struct List *)GenericListTable[GLIST_WAIT])
  269.         UnlockGenericList((struct GenericList *)MatchList);
  270.  
  271.     Unlock_xOFF();
  272.  
  273.     StopTime();
  274.  
  275.     if(Result)
  276.         return(CreateResult(Result,ResultCode));
  277.     else
  278.         return(NULL);
  279. }
  280.  
  281. STATIC BOOL
  282. ExamineBeforeSending(STRPTR FileName,struct FileTransferInfo *Info,LONG *Results)
  283. {
  284.     BPTR FileLock;
  285.     BOOL Result;
  286.  
  287.     Result = FALSE;
  288.  
  289.     if(FileLock = Lock(FileName,ACCESS_READ))
  290.     {
  291.         D_S(struct FileInfoBlock,FileInfo);
  292.  
  293.         if(Examine(FileLock,FileInfo))
  294.         {
  295.             if(FileInfo->fib_DirEntryType < 0)
  296.             {
  297.                 UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  298.  
  299.                 if(NameFromLock(FileLock,LocalBuffer,sizeof(LocalBuffer)))
  300.                 {
  301.                     if(AddFileTransferNode(Info,LocalBuffer,FileInfo->fib_Size))
  302.                         Result = TRUE;
  303.                     else
  304.                     {
  305.                         Results[0] = RC_ERROR;
  306.                         Results[1] = ERROR_NO_FREE_STORE;
  307.                     }
  308.                 }
  309.                 else
  310.                 {
  311.                     Results[0] = RC_ERROR;
  312.                     Results[1] = IoErr();
  313.                 }
  314.             }
  315.             else
  316.             {
  317.                 Results[0] = RC_ERROR;
  318.                 Results[1] = ERROR_OBJECT_WRONG_TYPE;
  319.             }
  320.         }
  321.         else
  322.         {
  323.             Results[0] = RC_ERROR;
  324.             Results[1] = IoErr();
  325.         }
  326.  
  327.         UnLock(FileLock);
  328.     }
  329.     else
  330.     {
  331.         Results[0] = RC_ERROR;
  332.         Results[1] = IoErr();
  333.     }
  334.  
  335.     return(Result);
  336. }
  337.  
  338. STATIC BPTR
  339. ChangeDirBeforeSending(LONG Mode)
  340. {
  341.     BPTR NewDir = NULL;
  342.  
  343.     switch(Mode)
  344.     {
  345.         case TRANSFER_BINARY:
  346.  
  347.             if(Config->PathConfig->BinaryUploadPath[0])
  348.                 NewDir = Lock(Config->PathConfig->BinaryUploadPath,SHARED_LOCK);
  349.  
  350.             break;
  351.  
  352.         case TRANSFER_TEXT:
  353.  
  354.             if(Config->PathConfig->TextUploadPath[0])
  355.                 NewDir = Lock(Config->PathConfig->TextUploadPath,SHARED_LOCK);
  356.  
  357.             break;
  358.  
  359.         case TRANSFER_ASCII:
  360.  
  361.             if(Config->PathConfig->ASCIIUploadPath[0])
  362.                 NewDir = Lock(Config->PathConfig->ASCIIUploadPath,SHARED_LOCK);
  363.  
  364.             break;
  365.     }
  366.  
  367.     return(NewDir);
  368. }
  369.  
  370. STRPTR
  371. RexxSendFile(struct RexxPkt *Pkt)
  372. {
  373.     enum    {    ARG_SENDFILE_MODE,ARG_SENDFILE_NAMES };
  374.  
  375.     LONG Mode = TRANSFER_BINARY;
  376.  
  377.     if(Args[ARG_SENDFILE_MODE])
  378.         Mode = ToMode(Args[ARG_SENDFILE_MODE]);
  379.  
  380.     if(Mode == -1)
  381.     {
  382.         ResultCode[0] = RC_ERROR;
  383.         ResultCode[1] = ERROR_ACTION_NOT_KNOWN;
  384.     }
  385.     else
  386.     {
  387.         struct FileTransferInfo    *Info;
  388.         LONG FilesFound = 0;
  389.  
  390.         ResultCode[0] = RC_OK;
  391.  
  392.         if(Info = AllocFileTransferInfo())
  393.         {
  394.             struct GenericList *List = GenericListTable[GLIST_UPLOAD];
  395.             BPTR NewDir,OldDir;
  396.  
  397.             if(Args[ARG_SENDFILE_NAMES])
  398.             {
  399.                 STRPTR *Names;
  400.  
  401.                 Names = (STRPTR *)Args[ARG_SENDFILE_NAMES];
  402.  
  403.                 if(NewDir = ChangeDirBeforeSending(Mode))
  404.                     OldDir = CurrentDir(NewDir);
  405.  
  406.                 while(*Names && ResultCode[0] == RC_OK)
  407.                 {
  408.                     if(ExamineBeforeSending(*Names++,Info,ResultCode))
  409.                         FilesFound++;
  410.                 }
  411.  
  412.                 if(NewDir)
  413.                     UnLock(CurrentDir(OldDir));
  414.             }
  415.  
  416.             LockGenericList(List);
  417.  
  418.             if(GenericListCount(List) > 0 && ResultCode[0] == RC_OK)
  419.             {
  420.                 struct Node    *Node;
  421.  
  422.                 if(NewDir = ChangeDirBeforeSending(Mode))
  423.                     OldDir = CurrentDir(NewDir);
  424.  
  425.                 for(Node = (struct Node *)List->ListHeader.mlh_Head ; Node->ln_Succ && ResultCode[0] == RC_OK ; Node = Node->ln_Succ)
  426.                 {
  427.                     if(ExamineBeforeSending(Node->ln_Name,Info,ResultCode))
  428.                         FilesFound++;
  429.                 }
  430.  
  431.                 if(NewDir)
  432.                     UnLock(CurrentDir(OldDir));
  433.             }
  434.  
  435.             UnlockGenericList(List);
  436.  
  437.             if(ResultCode[0] == RC_OK)
  438.             {
  439.                 BlockWindows();
  440.  
  441.                 if(FilesFound)
  442.                 {
  443.                     ReadyFileTransferInfo(Info,TRUE);
  444.  
  445.                     FileTransferInfo = Info;
  446.                 }
  447.  
  448.                 switch(Mode)
  449.                 {
  450.                     case TRANSFER_ASCII:
  451.  
  452.                         if(ChangeProtocol(Config->TransferConfig->ASCIIUploadLibrary,Config->TransferConfig->ASCIIUploadType))
  453.                         {
  454.                             if(FilesFound)
  455.                                 StartSendXPR_FromList(TRANSFER_ASCII,FALSE);
  456.                             else
  457.                                 StartSendXPR_AskForFile(TRANSFER_ASCII,FALSE);
  458.                         }
  459.                         else
  460.                         {
  461.                             ResultCode[0] = RC_ERROR;
  462.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  463.                         }
  464.  
  465.                         ResetProtocol();
  466.  
  467.                         break;
  468.  
  469.                     case TRANSFER_TEXT:
  470.  
  471.                         if(ChangeProtocol(Config->TransferConfig->TextUploadLibrary,Config->TransferConfig->TextUploadType))
  472.                         {
  473.                             if(FilesFound)
  474.                                 StartSendXPR_FromList(TRANSFER_TEXT,FALSE);
  475.                             else
  476.                                 StartSendXPR_AskForFile(TRANSFER_TEXT,FALSE);
  477.                         }
  478.                         else
  479.                         {
  480.                             ResultCode[0] = RC_ERROR;
  481.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  482.                         }
  483.  
  484.                         ResetProtocol();
  485.  
  486.                         break;
  487.  
  488.                     case TRANSFER_BINARY:
  489.  
  490.                         if(ChangeProtocol(Config->TransferConfig->BinaryUploadLibrary,Config->TransferConfig->BinaryUploadType))
  491.                         {
  492.                             if(FilesFound)
  493.                                 StartSendXPR_FromList(TRANSFER_BINARY,FALSE);
  494.                             else
  495.                                 StartSendXPR_AskForFile(TRANSFER_BINARY,FALSE);
  496.                         }
  497.                         else
  498.                         {
  499.                             ResultCode[0] = RC_ERROR;
  500.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  501.                         }
  502.  
  503.                         ResetProtocol();
  504.  
  505.                         break;
  506.                 }
  507.  
  508.                 if(TransferFailed)
  509.                     ResultCode[0] = RC_ERROR;
  510.                 else
  511.                 {
  512.                     if(TransferAborted)
  513.                         ResultCode[0] = RC_WARN;
  514.                 }
  515.  
  516.                 ReleaseWindows();
  517.             }
  518.             else
  519.                 FreeFileTransferInfo(Info);
  520.         }
  521.         else
  522.         {
  523.             ResultCode[0] = RC_ERROR;
  524.             ResultCode[1] = ERROR_NO_FREE_STORE;
  525.         }
  526.     }
  527.  
  528.     return(NULL);
  529. }
  530.  
  531. STRPTR
  532. RexxSelect(struct RexxPkt *Pkt)
  533. {
  534.     enum    {    ARG_SELECT_NAME,ARG_SELECT_FROM,ARG_SELECT_NEXT,ARG_SELECT_PREVIOUS,
  535.                 ARG_SELECT_TOP,ARG_SELECT_BOTTOM
  536.             };
  537.  
  538.     LONG Index;
  539.  
  540.     if((Index = ToList(Args[ARG_SELECT_FROM])) == -1)
  541.     {
  542.         ResultCode[0] = RC_ERROR;
  543.         ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  544.     }
  545.     else
  546.     {
  547.         if(Args[ARG_SELECT_NAME] && Index == GLIST_DIAL)
  548.         {
  549.             ResultCode[0] = RC_ERROR;
  550.             ResultCode[1] = TERMERROR_DATA_TYPES_INCOMPATIBLE;
  551.         }
  552.         else
  553.         {
  554.             struct GenericList *List;
  555.             STRPTR Result;
  556.  
  557.             List = GenericListTable[Index];
  558.  
  559.             if(Args[ARG_SELECT_NAME])
  560.             {
  561.                 STRPTR Buffer;
  562.  
  563.                 if(Buffer = CreateMatchBuffer(Args[ARG_SELECT_NAME]))
  564.                 {
  565.                     struct Node *Node;
  566.                     BOOL GotIt;
  567.  
  568.                     LockGenericList(List);
  569.  
  570.                     for(Node = (struct Node *)List->ListHeader.mlh_Head, GotIt = FALSE; !GotIt && Node->ln_Succ ; Node = Node->ln_Succ)
  571.                     {
  572.                         if(MatchBuffer(Buffer,Node->ln_Name))
  573.                         {
  574.                             List->ListNode = Node;
  575.  
  576.                             GotIt = TRUE;
  577.                         }
  578.                     }
  579.  
  580.                     if(!GotIt)
  581.                         ResultCode[0] = RC_WARN;
  582.  
  583.                     UnlockGenericList(List);
  584.  
  585.                     DeleteMatchBuffer(Buffer);
  586.                 }
  587.                 else
  588.                 {
  589.                     ResultCode[0] = RC_ERROR;
  590.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  591.                 }
  592.             }
  593.             else
  594.             {
  595.                 if(Args[ARG_SELECT_NEXT])
  596.                 {
  597.                     if(!NextGenericListNode(List))
  598.                     {
  599.                         ResultCode[0] = RC_WARN;
  600.  
  601.                         return(NULL);
  602.                     }
  603.                 }
  604.  
  605.                 if(Args[ARG_SELECT_PREVIOUS])
  606.                 {
  607.                     if(!PrevGenericListNode(List))
  608.                     {
  609.                         ResultCode[0] = RC_WARN;
  610.  
  611.                         return(NULL);
  612.                     }
  613.                 }
  614.  
  615.                 if(Args[ARG_SELECT_TOP])
  616.                 {
  617.                     if(!FirstGenericListNode(List))
  618.                     {
  619.                         ResultCode[0] = RC_WARN;
  620.  
  621.                         return(NULL);
  622.                     }
  623.                 }
  624.  
  625.                 if(Args[ARG_SELECT_BOTTOM])
  626.                 {
  627.                     if(!LastGenericListNode(List))
  628.                     {
  629.                         ResultCode[0] = RC_WARN;
  630.  
  631.                         return(NULL);
  632.                     }
  633.                 }
  634.             }
  635.  
  636.             SharedLockGenericList(List);
  637.  
  638.             if(List->ListNode)
  639.                 Result = CreateResult(((struct Node *)List->ListNode)->ln_Name,ResultCode);
  640.             else
  641.             {
  642.                 ResultCode[0] = RC_WARN;
  643.  
  644.                 Result = NULL;
  645.             }
  646.  
  647.             UnlockGenericList(List);
  648.  
  649.             return(Result);
  650.         }
  651.     }
  652.  
  653.     return(NULL);
  654. }
  655.  
  656. STRPTR
  657. RexxSaveAs(struct RexxPkt *Pkt)
  658. {
  659.     enum    {    ARG_SAVEAS_NAME,ARG_SAVEAS_FROM };
  660.  
  661.     LONG Index = ToConfig(Args[ARG_SAVEAS_FROM]);
  662.  
  663.     if(Index == -1)
  664.     {
  665.         ResultCode[0] = RC_ERROR;
  666.         ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  667.     }
  668.     else
  669.     {
  670.         UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  671.         STRPTR FileName;
  672.  
  673.         if(Args[ARG_SAVEAS_NAME])
  674.             FileName = Args[ARG_SAVEAS_NAME];
  675.         else
  676.         {
  677.             struct FileRequester *FileRequest;
  678.             LONG TitleID;
  679.  
  680.             FileName = NULL;
  681.  
  682.             switch(Index)
  683.             {
  684.                 case DATATYPE_TRANSLATIONS:
  685.  
  686.                     TitleID = MSG_TRANSLATIONPANEL_SAVE_TRANSLATION_TABLES_TXT;
  687.                     break;
  688.  
  689.                 case DATATYPE_FUNCTIONKEYS:
  690.  
  691.                     TitleID = MSG_MACROPANEL_SAVE_MACRO_KEYS_TXT;
  692.                     break;
  693.  
  694.                 case DATATYPE_CURSORKEYS:
  695.  
  696.                     TitleID = MSG_CURSORPANEL_SAVE_CURSOR_KEYS_TXT;
  697.                     break;
  698.  
  699.                 case DATATYPE_FASTMACROS:
  700.  
  701.                     TitleID = MSG_FASTMACROPANEL_SAVE_FAST_MACRO_SETTINGS_TXT;
  702.                     break;
  703.  
  704.                 case DATATYPE_HOTKEYS:
  705.  
  706.                     TitleID = MSG_HOTKEYPANEL_SAVE_HOTKEYS_TXT;
  707.                     break;
  708.  
  709.                 case DATATYPE_SPEECH:
  710.  
  711.                     TitleID = MSG_SPEECHPANEL_SAVE_SPEECH_SETTINGS_TXT;
  712.                     break;
  713.  
  714.                 case DATATYPE_SOUND:
  715.  
  716.                     TitleID = MSG_SOUNDPANEL_SAVE_SOUNDS_TXT;
  717.                     break;
  718.  
  719.                 case DATATYPE_BUFFER:
  720.  
  721.                     TitleID = MSG_TERMMAIN_SAVE_BUFFER_TXT;
  722.                     break;
  723.  
  724.                 case DATATYPE_CONFIGURATION:
  725.  
  726.                     TitleID = MSG_TERMMAIN_SAVE_PREFERENCES_AS_TXT;
  727.                     break;
  728.  
  729.                 case DATATYPE_PHONEBOOK:
  730.  
  731.                     TitleID = MSG_PHONEPANEL_SAVE_PHONEBOOK_TXT;
  732.                     break;
  733.  
  734.                 case DATATYPE_SCREENTEXT:
  735.  
  736.                     TitleID = MSG_TERMMAIN_SAVE_SCREEN_ASCII_TXT;
  737.                     break;
  738.  
  739.                 case DATATYPE_SCREENIMAGE:
  740.  
  741.                     TitleID = MSG_TERMMAIN_SAVE_SCREEN_IFF_TXT;
  742.                     break;
  743.             }
  744.  
  745.             BlockWindows();
  746.  
  747.             DummyBuffer[0] = 0;
  748.  
  749.             if(FileRequest = SaveFile(Window,LocaleString(TitleID),NULL,NULL,DummyBuffer,sizeof(DummyBuffer)))
  750.             {
  751.                 FreeAslRequest(FileRequest);
  752.  
  753.                 FileName = DummyBuffer;
  754.             }
  755.  
  756.             ReleaseWindows();
  757.         }
  758.  
  759.         if(FileName)
  760.         {
  761.             switch(Index)
  762.             {
  763.                 case DATATYPE_TRANSLATIONS:
  764.  
  765.                     if(SendTable && ReceiveTable)
  766.                     {
  767.                         if(!SaveTranslationTables(FileName,SendTable,ReceiveTable))
  768.                         {
  769.                             ResultCode[0] = RC_ERROR;
  770.                             ResultCode[1] = IoErr();
  771.                         }
  772.                         else
  773.                         {
  774.                             strcpy(LastTranslation,FileName);
  775.  
  776.                             strcpy(Config->TranslationFileName,LastTranslation);
  777.  
  778.                             TranslationChanged = FALSE;
  779.                         }
  780.                     }
  781.                     else
  782.                         ResultCode[0] = RC_WARN;
  783.  
  784.                     break;
  785.  
  786.                 case DATATYPE_FUNCTIONKEYS:
  787.  
  788.                     if(!WriteIFFData(FileName,MacroKeys,sizeof(struct MacroKeys),ID_KEYS))
  789.                     {
  790.                         ResultCode[0] = RC_ERROR;
  791.                         ResultCode[1] = IoErr();
  792.                     }
  793.                     else
  794.                     {
  795.                         strcpy(LastMacros,FileName);
  796.  
  797.                         strcpy(Config->MacroFileName,LastMacros);
  798.  
  799.                         MacroChanged = FALSE;
  800.                     }
  801.  
  802.                     break;
  803.  
  804.                 case DATATYPE_CURSORKEYS:
  805.  
  806.                     if(!WriteIFFData(FileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  807.                     {
  808.                         ResultCode[0] = RC_ERROR;
  809.                         ResultCode[1] = IoErr();
  810.                     }
  811.                     else
  812.                     {
  813.                         strcpy(LastCursorKeys,FileName);
  814.  
  815.                         strcpy(Config->CursorFileName,LastCursorKeys);
  816.  
  817.                         CursorKeysChanged = FALSE;
  818.                     }
  819.  
  820.                     break;
  821.  
  822.                 case DATATYPE_FASTMACROS:
  823.  
  824.                     if(!SaveFastMacros(FileName,&FastMacroList))
  825.                     {
  826.                         ResultCode[0] = RC_ERROR;
  827.                         ResultCode[1] = IoErr();
  828.                     }
  829.                     else
  830.                     {
  831.                         strcpy(LastFastMacros,FileName);
  832.  
  833.                         strcpy(Config->FastMacroFileName,LastFastMacros);
  834.  
  835.                         FastMacrosChanged = FALSE;
  836.                     }
  837.  
  838.                     break;
  839.  
  840.                 case DATATYPE_HOTKEYS:
  841.  
  842.                     if(!WriteIFFData(FileName,&Hotkeys,sizeof(struct Hotkeys),ID_HOTK))
  843.                     {
  844.                         ResultCode[0] = RC_ERROR;
  845.                         ResultCode[1] = IoErr();
  846.                     }
  847.                     else
  848.                     {
  849.                         strcpy(LastKeys,FileName);
  850.  
  851.                         strcpy(Config->HotkeyFileName,LastKeys);
  852.  
  853.                         HotkeysChanged = FALSE;
  854.                     }
  855.  
  856.                     break;
  857.  
  858.                 case DATATYPE_SPEECH:
  859.  
  860.                     if(!WriteIFFData(FileName,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  861.                     {
  862.                         ResultCode[0] = RC_ERROR;
  863.                         ResultCode[1] = IoErr();
  864.                     }
  865.                     else
  866.                     {
  867.                         strcpy(LastSpeech,FileName);
  868.  
  869.                         strcpy(Config->SpeechFileName,LastSpeech);
  870.  
  871.                         SpeechChanged = FALSE;
  872.                     }
  873.  
  874.                     break;
  875.  
  876.                 case DATATYPE_SOUND:
  877.  
  878.                     if(!WriteIFFData(FileName,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  879.                     {
  880.                         ResultCode[0] = RC_ERROR;
  881.                         ResultCode[1] = IoErr();
  882.                     }
  883.                     else
  884.                     {
  885.                         strcpy(LastSound,FileName);
  886.  
  887.                         strcpy(Config->SoundFileName,LastSound);
  888.  
  889.                         SoundChanged = FALSE;
  890.                     }
  891.  
  892.                     break;
  893.  
  894.                 case DATATYPE_BUFFER:
  895.  
  896.                     if(BufferLines && Lines)
  897.                     {
  898.                         BPTR SomeFile;
  899.  
  900.                         if(SomeFile = OpenToAppend(FileName,NULL))
  901.                         {
  902.                             LONG i,Len;
  903.  
  904.                                 /* Obtain the semaphore required
  905.                                  * to gain access to the line buffer
  906.                                  */
  907.  
  908.                             SafeObtainSemaphoreShared(&BufferSemaphore);
  909.  
  910.                             for(i = 0 ; i < Lines ; i++)
  911.                             {
  912.                                 Len = BufferLines[i][-1];
  913.  
  914.                                 if(Len)
  915.                                 {
  916.                                     if(FWrite(SomeFile,BufferLines[i],Len,1) != 1)
  917.                                     {
  918.                                         ResultCode[0] = RC_ERROR;
  919.                                         ResultCode[1] = IoErr();
  920.  
  921.                                         break;
  922.                                     }
  923.                                 }
  924.  
  925.                                 if(FPrintf(SomeFile,"\n") < 1)
  926.                                 {
  927.                                     ResultCode[0] = RC_ERROR;
  928.                                     ResultCode[1] = IoErr();
  929.  
  930.                                     break;
  931.                                 }
  932.                             }
  933.  
  934.                             ReleaseSemaphore(&BufferSemaphore);
  935.  
  936.                             Close(SomeFile);
  937.  
  938.                             AddProtection(FileName,FIBF_EXECUTE);
  939.  
  940.                             if(Config->MiscConfig->CreateIcons)
  941.                                 AddIcon(FileName,FILETYPE_TEXT,TRUE);
  942.  
  943.                             BufferChanged = FALSE;
  944.                         }
  945.                         else
  946.                         {
  947.                             ResultCode[0] = RC_ERROR;
  948.                             ResultCode[1] = IoErr();
  949.                         }
  950.                     }
  951.                     else
  952.                     {
  953.                         ResultCode[0] = RC_ERROR;
  954.                         ResultCode[1] = TERMERROR_NO_DATA_TO_PROCESS;
  955.                     }
  956.  
  957.                     break;
  958.  
  959.                 case DATATYPE_CONFIGURATION:
  960.  
  961.                     if(!WriteConfig(FileName,Config))
  962.                     {
  963.                         ResultCode[0] = RC_ERROR;
  964.                         ResultCode[1] = IoErr();
  965.                     }
  966.                     else
  967.                     {
  968.                         strcpy(LastConfig,FileName);
  969.  
  970.                         ConfigChanged = FALSE;
  971.                     }
  972.  
  973.                     break;
  974.  
  975.                 case DATATYPE_PHONEBOOK:
  976.  
  977.                     if(!SavePhonebook(FileName,GlobalPhoneHandle))
  978.                     {
  979.                         ResultCode[0] = RC_ERROR;
  980.                         ResultCode[1] = IoErr();
  981.                     }
  982.                     else
  983.                     {
  984.                         strcpy(LastPhone,FileName);
  985.                         strcpy(Config->PhonebookFileName,LastPhone);
  986.  
  987.                         PhonebookChanged = FALSE;
  988.                     }
  989.  
  990.                     break;
  991.  
  992.                 case DATATYPE_SCREENTEXT:
  993.  
  994.                     if(RasterEnabled)
  995.                     {
  996.                         BPTR SomeFile;
  997.  
  998.                         if(SomeFile = OpenToAppend(FileName,NULL))
  999.                         {
  1000.                             LONG     i,j;
  1001.                             UBYTE    *Buffer;
  1002.  
  1003.                             for(i = 0 ; i < RasterHeight ; i++)
  1004.                             {
  1005.                                 Buffer = &Raster[i * RasterWidth];
  1006.  
  1007.                                 j = LastColumn;
  1008.  
  1009.                                 while(j >= 0 && Buffer[j] == ' ')
  1010.                                     j--;
  1011.  
  1012.                                 if(j >= 0)
  1013.                                 {
  1014.                                     if(!FWrite(SomeFile,Buffer,j + 1,1))
  1015.                                     {
  1016.                                         ResultCode[0] = RC_ERROR;
  1017.                                         ResultCode[1] = IoErr();
  1018.  
  1019.                                         break;
  1020.                                     }
  1021.                                 }
  1022.  
  1023.                                 if(!FWrite(SomeFile,"\n",1,1))
  1024.                                 {
  1025.                                     ResultCode[0] = RC_ERROR;
  1026.                                     ResultCode[1] = IoErr();
  1027.  
  1028.                                     break;
  1029.                                 }
  1030.                             }
  1031.  
  1032.                             Close(SomeFile);
  1033.  
  1034.                             AddProtection(FileName,FIBF_EXECUTE);
  1035.  
  1036.                             if(Config->MiscConfig->CreateIcons)
  1037.                                 AddIcon(FileName,FILETYPE_TEXT,TRUE);
  1038.                         }
  1039.                         else
  1040.                         {
  1041.                             ResultCode[0] = RC_ERROR;
  1042.                             ResultCode[1] = IoErr();
  1043.                         }
  1044.                     }
  1045.                     else
  1046.                     {
  1047.                         ResultCode[0] = RC_ERROR;
  1048.                         ResultCode[1] = TERMERROR_NO_DATA_TO_PROCESS;
  1049.                     }
  1050.  
  1051.                     break;
  1052.  
  1053.                 case DATATYPE_SCREENIMAGE:
  1054.  
  1055.                     if(!SaveWindow(FileName,Window))
  1056.                     {
  1057.                         ResultCode[0] = RC_ERROR;
  1058.                         ResultCode[1] = IoErr();
  1059.                     }
  1060.  
  1061.                     break;
  1062.             }
  1063.         }
  1064.         else
  1065.             ResultCode[0] = RC_WARN;
  1066.     }
  1067.  
  1068.     return(NULL);
  1069. }
  1070.  
  1071. STRPTR
  1072. RexxRemove(struct RexxPkt *Pkt)
  1073. {
  1074.     enum    {    ARG_REMOVE_FROM,ARG_REMOVE_NAME };
  1075.  
  1076.     LONG Index;
  1077.  
  1078.     if((Index = ToList(Args[ARG_REMOVE_FROM])) == -1)
  1079.     {
  1080.         ResultCode[0] = RC_ERROR;
  1081.         ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  1082.     }
  1083.     else
  1084.     {
  1085.         if(Args[ARG_REMOVE_NAME] && Index == GLIST_DIAL)
  1086.         {
  1087.             ResultCode[0] = RC_ERROR;
  1088.             ResultCode[1] = TERMERROR_DATA_TYPES_INCOMPATIBLE;
  1089.         }
  1090.         else
  1091.         {
  1092.             struct GenericList *List;
  1093.  
  1094.             List = GenericListTable[Index];
  1095.  
  1096.             if(Args[ARG_REMOVE_NAME])
  1097.             {
  1098.                 STRPTR Buffer;
  1099.  
  1100.                 if(Buffer = CreateMatchBuffer(Args[ARG_REMOVE_NAME]))
  1101.                 {
  1102.                     struct Node *Node,*Next;
  1103.  
  1104.                     LockGenericList(List);
  1105.  
  1106.                     for(Node = (struct Node *)List->ListHeader.mlh_Head ; Next = Node->ln_Succ ; Node = Next)
  1107.                     {
  1108.                         if(MatchBuffer(Buffer,Node->ln_Name))
  1109.                         {
  1110.                             Forbid();
  1111.  
  1112.                             UnlockGenericList(List);
  1113.  
  1114.                             DeleteGenericListNode(List,Node,TRUE);
  1115.  
  1116.                             LockGenericList(List);
  1117.  
  1118.                             Permit();
  1119.                         }
  1120.                     }
  1121.  
  1122.                     UnlockGenericList(List);
  1123.  
  1124.                     DeleteMatchBuffer(Buffer);
  1125.                 }
  1126.                 else
  1127.                 {
  1128.                     ResultCode[0] = RC_ERROR;
  1129.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  1130.                 }
  1131.             }
  1132.             else
  1133.                 DeleteGenericListNode(List,NULL,TRUE);
  1134.  
  1135.             if(!GenericListCount(List))
  1136.                 ResultCode[0] = RC_WARN;
  1137.         }
  1138.     }
  1139.  
  1140.     return(NULL);
  1141. }
  1142.  
  1143. STRPTR
  1144. RexxRequestFile(struct RexxPkt *Pkt)
  1145. {
  1146.     enum    {    ARG_REQUESTFILE_TITLE,ARG_REQUESTFILE_PATH,ARG_REQUESTFILE_FILE,
  1147.                 ARG_REQUESTFILE_PATTERN,ARG_REQUESTFILE_MULTI,ARG_REQUESTFILE_NAME
  1148.             };
  1149.  
  1150.     if(Args[ARG_REQUESTFILE_MULTI] && !Args[ARG_REQUESTFILE_NAME])
  1151.     {
  1152.         ResultCode[0] = RC_ERROR;
  1153.         ResultCode[1] = TERMERROR_RESULT_VARIABLE_REQUIRED;
  1154.     }
  1155.     else
  1156.     {
  1157.         UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  1158.         struct FileRequester *FileRequester;
  1159.  
  1160.         if(Args[ARG_REQUESTFILE_PATH])
  1161.         {
  1162.             LimitedStrcpy(sizeof(DummyBuffer),DummyBuffer,Args[ARG_REQUESTFILE_PATH]);
  1163.  
  1164.             if(Args[ARG_REQUESTFILE_FILE])
  1165.                 AddPart(DummyBuffer,Args[ARG_REQUESTFILE_FILE],sizeof(DummyBuffer));
  1166.         }
  1167.         else
  1168.         {
  1169.             if(Args[ARG_REQUESTFILE_FILE])
  1170.                 LimitedStrcpy(sizeof(DummyBuffer),DummyBuffer,Args[ARG_REQUESTFILE_FILE]);
  1171.             else
  1172.                 DummyBuffer[0] = 0;
  1173.         }
  1174.  
  1175.         BlockWindows();
  1176.  
  1177.         if(Args[ARG_REQUESTFILE_MULTI])
  1178.             FileRequester = OpenSeveralFiles(Window,Args[ARG_REQUESTFILE_TITLE],NULL,Args[ARG_REQUESTFILE_PATTERN],DummyBuffer,sizeof(DummyBuffer));
  1179.         else
  1180.             FileRequester = OpenSingleFile(Window,Args[ARG_REQUESTFILE_TITLE],NULL,Args[ARG_REQUESTFILE_PATTERN],DummyBuffer,sizeof(DummyBuffer));
  1181.  
  1182.         if(FileRequester)
  1183.         {
  1184.             if(Args[ARG_REQUESTFILE_NAME])
  1185.             {
  1186.                 if(Args[ARG_REQUESTFILE_MULTI])
  1187.                 {
  1188.                     struct WBArg *ArgList = FileRequester->fr_ArgList;
  1189.                     UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  1190.                     LONG i,Counted = 0;
  1191.  
  1192.                     for(i = 0 ; i < FileRequester->fr_NumArgs ; i++)
  1193.                     {
  1194.                         if(ArgList[i].wa_Name)
  1195.                         {
  1196.                             if(ArgList[i].wa_Lock)
  1197.                             {
  1198.                                 if(!NameFromLock(ArgList[i].wa_Lock,LocalBuffer,sizeof(LocalBuffer)))
  1199.                                 {
  1200.                                     ResultCode[0] = RC_ERROR;
  1201.                                     ResultCode[1] = IoErr();
  1202.  
  1203.                                     break;
  1204.                                 }
  1205.                             }
  1206.                             else
  1207.                                 strcpy(LocalBuffer,FileRequester->fr_Drawer);
  1208.  
  1209.                             if(AddPart(LocalBuffer,ArgList[i].wa_Name,sizeof(LocalBuffer)))
  1210.                             {
  1211.                                 if(CreateVarArgs(LocalBuffer,Pkt,"%s.%ld",Args[ARG_REQUESTFILE_NAME],i))
  1212.                                     Counted++;
  1213.                                 else
  1214.                                     break;
  1215.                             }
  1216.                             else
  1217.                             {
  1218.                                 ResultCode[0] = RC_ERROR;
  1219.                                 ResultCode[1] = IoErr();
  1220.  
  1221.                                 break;
  1222.                             }
  1223.                         }
  1224.                     }
  1225.  
  1226.                     if(Counted)
  1227.                     {
  1228.                         LimitedSPrintf(sizeof(LocalBuffer),LocalBuffer,"%ld",Counted);
  1229.  
  1230.                         CreateVarArgs(LocalBuffer,Pkt,"%s.COUNT",Args[ARG_REQUESTFILE_NAME]);
  1231.                     }
  1232.  
  1233.                     FreeAslRequest(FileRequester);
  1234.                 }
  1235.                 else
  1236.                 {
  1237.                     FreeAslRequest(FileRequester);
  1238.  
  1239.                     ReleaseWindows();
  1240.  
  1241.                     return(CreateVar(DummyBuffer,Pkt,Args[ARG_REQUESTFILE_NAME]));
  1242.                 }
  1243.             }
  1244.             else
  1245.             {
  1246.                 FreeAslRequest(FileRequester);
  1247.  
  1248.                 ReleaseWindows();
  1249.  
  1250.                 return(CreateResult(DummyBuffer,ResultCode));
  1251.             }
  1252.         }
  1253.         else
  1254.             ResultCode[0] = RC_WARN;
  1255.  
  1256.         ReleaseWindows();
  1257.     }
  1258.  
  1259.     return(NULL);
  1260. }
  1261.  
  1262. STRPTR
  1263. RexxReceiveFile(struct RexxPkt *Pkt)
  1264. {
  1265.     enum    {    ARG_RECEIVEFILE_MODE,ARG_RECEIVEFILE_NAME };
  1266.  
  1267.     LONG    Mode = TRANSFER_BINARY;
  1268.     STRPTR    Name = (STRPTR)Args[ARG_RECEIVEFILE_NAME];
  1269.  
  1270.     if(Args[ARG_RECEIVEFILE_MODE])
  1271.         Mode = ToMode(Args[ARG_RECEIVEFILE_MODE]);
  1272.  
  1273.     if(Mode == -1)
  1274.     {
  1275.         ResultCode[0] = RC_ERROR;
  1276.         ResultCode[1] = ERROR_ACTION_NOT_KNOWN;
  1277.     }
  1278.     else
  1279.     {
  1280.         BlockWindows();
  1281.  
  1282.         switch(Mode)
  1283.         {
  1284.             case TRANSFER_ASCII:
  1285.  
  1286.                 if(ChangeProtocol(Config->TransferConfig->ASCIIDownloadLibrary,Config->TransferConfig->ASCIIDownloadType))
  1287.                 {
  1288.                     StartReceiveXPR_File(TRANSFER_ASCII,Name,FALSE);
  1289.  
  1290.                     SerialCommand(Config->CommandConfig->DownloadMacro);
  1291.                 }
  1292.                 else
  1293.                 {
  1294.                     ResultCode[0] = RC_ERROR;
  1295.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  1296.                 }
  1297.  
  1298.                 ResetProtocol();
  1299.  
  1300.                 break;
  1301.  
  1302.             case TRANSFER_TEXT:
  1303.  
  1304.                 if(ChangeProtocol(Config->TransferConfig->TextDownloadLibrary,Config->TransferConfig->TextDownloadType))
  1305.                 {
  1306.                     StartReceiveXPR_File(TRANSFER_TEXT,Name,FALSE);
  1307.  
  1308.                     SerialCommand(Config->CommandConfig->DownloadMacro);
  1309.                 }
  1310.                 else
  1311.                 {
  1312.                     ResultCode[0] = RC_ERROR;
  1313.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  1314.                 }
  1315.  
  1316.                 ResetProtocol();
  1317.  
  1318.                 break;
  1319.  
  1320.             case TRANSFER_BINARY:
  1321.  
  1322.                 if(ChangeProtocol(Config->TransferConfig->BinaryDownloadLibrary,Config->TransferConfig->BinaryDownloadType))
  1323.                 {
  1324.                     StartReceiveXPR_File(TRANSFER_BINARY,Name,FALSE);
  1325.  
  1326.                     SerialCommand(Config->CommandConfig->DownloadMacro);
  1327.                 }
  1328.                 else
  1329.                 {
  1330.                     ResultCode[0] = RC_ERROR;
  1331.                     ResultCode[1] = ERROR_NO_FREE_STORE;
  1332.                 }
  1333.  
  1334.                 ResetProtocol();
  1335.  
  1336.                 break;
  1337.         }
  1338.  
  1339.         if(TransferFailed)
  1340.             ResultCode[0] = RC_ERROR;
  1341.         else
  1342.         {
  1343.             if(TransferAborted)
  1344.                 ResultCode[0] = RC_WARN;
  1345.         }
  1346.  
  1347.         ReleaseWindows();
  1348.     }
  1349.  
  1350.     return(NULL);
  1351. }
  1352.  
  1353. STRPTR
  1354. RexxPrint(struct RexxPkt *Pkt)
  1355. {
  1356.     enum    {    ARG_PRINT_FROM,ARG_PRINT_TO,ARG_PRINT_SERIAL,ARG_PRINT_MODEM,ARG_PRINT_SCREEN,
  1357.                 ARG_PRINT_TERMINAL,ARG_PRINT_USER,ARG_PRINT_COMMENT,ARG_PRINT_SIZE,
  1358.                 ARG_PRINT_DATE,ARG_PRINT_BITS
  1359.             };
  1360.  
  1361.     LONG    Index,Mode = -1;
  1362.     ULONG    Flags = NULL;
  1363.  
  1364.     if(Args[ARG_PRINT_SERIAL])
  1365.         Flags |= PRINT_SERIAL;
  1366.  
  1367.     if(Args[ARG_PRINT_MODEM])
  1368.         Flags |= PRINT_MODEM;
  1369.  
  1370.     if(Args[ARG_PRINT_SCREEN])
  1371.         Flags |= PRINT_SCREEN;
  1372.  
  1373.     if(Args[ARG_PRINT_TERMINAL])
  1374.         Flags |= PRINT_TERMINAL;
  1375.  
  1376.     if(Args[ARG_PRINT_USER])
  1377.         Flags |= PRINT_USERNAME;
  1378.  
  1379.     if(Args[ARG_PRINT_COMMENT])
  1380.         Flags |= PRINT_COMMENT;
  1381.  
  1382.     if(Args[ARG_PRINT_SIZE])
  1383.         Flags |= PRINT_SIZE;
  1384.  
  1385.     if(Args[ARG_PRINT_DATE])
  1386.         Flags |= PRINT_DATE;
  1387.  
  1388.     if(Args[ARG_PRINT_BITS])
  1389.         Flags |= PRINT_BITS;
  1390.  
  1391.     if((Index = ToList(Args[ARG_PRINT_FROM])) == -1)
  1392.     {
  1393.         if(!Stricmp(Args[ARG_PRINT_FROM],"SCREENTEXT"))
  1394.         {
  1395.             if(!RasterEnabled)
  1396.             {
  1397.                 ResultCode[0] = RC_ERROR;
  1398.                 ResultCode[1] = TERMERROR_NO_DATA_TO_PROCESS;
  1399.  
  1400.                 return(NULL);
  1401.             }
  1402.             else
  1403.                 Mode = 0;
  1404.         }
  1405.  
  1406.         if(!Stricmp(Args[ARG_PRINT_FROM],"CLIPBOARD"))
  1407.             Mode = 1;
  1408.  
  1409.         if(!Stricmp(Args[ARG_PRINT_FROM],"BUFFER"))
  1410.             Mode = 2;
  1411.     }
  1412.  
  1413.     if(Index == -1 && Mode == -1)
  1414.     {
  1415.         ResultCode[0] = RC_ERROR;
  1416.         ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  1417.     }
  1418.     else
  1419.     {
  1420.         BOOL Continue = TRUE;
  1421.         LONG Error = 0;
  1422.         STRPTR Name;
  1423.         BPTR File;
  1424.  
  1425.         if(Args[ARG_PRINT_TO])
  1426.             Name = Args[ARG_PRINT_TO];
  1427.         else
  1428.             Name = "PRT:";
  1429.  
  1430.         if(File = Open(Name,MODE_NEWFILE))
  1431.         {
  1432.             struct Window *ReqWindow;
  1433.             struct EasyStruct Easy;
  1434.  
  1435.             Easy.es_StructSize        = sizeof(struct EasyStruct);
  1436.             Easy.es_Flags            = NULL;
  1437.             Easy.es_Title            = (UBYTE *)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  1438.             Easy.es_GadgetFormat    = (UBYTE *)LocaleString(MSG_PRINT_STOP_TXT);
  1439.             Easy.es_TextFormat        = (UBYTE *)LocaleString(MSG_GLOBAL_PRINTING_TXT);
  1440.  
  1441.             BlockWindows();
  1442.  
  1443.             if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  1444.             {
  1445.                 struct GenericList *List;
  1446.  
  1447.                 switch(Index)
  1448.                 {
  1449.                     case GLIST_DIAL:
  1450.  
  1451.                         List = GenericListTable[Index];
  1452.  
  1453.                         LockGenericList(List);
  1454.  
  1455.                         if(GenericListCount(List) > 0)
  1456.                         {
  1457.                             struct GenericDialNode *Node;
  1458.  
  1459.                             for(Node = (struct GenericDialNode *)List->ListHeader.mlh_Head ; Continue && Node->Node.ln_Succ ; Node = (struct GenericDialNode *)Node->Node.ln_Succ)
  1460.                             {
  1461.                                 if(!Node->Index)
  1462.                                     Continue = PrintText(File,ReqWindow,&Error,"\n\"???\" (%s)",Node->Node.ln_Name);
  1463.                             }
  1464.                         }
  1465.  
  1466.                         UnlockGenericList(List);
  1467.  
  1468.                         break;
  1469.  
  1470.                     case GLIST_UPLOAD:
  1471.                     case GLIST_DOWNLOAD:
  1472.  
  1473.                         List = GenericListTable[Index];
  1474.  
  1475.                         LockGenericList(List);
  1476.  
  1477.                         if(GenericListCount(List) > 0)
  1478.                         {
  1479.                             struct Node *TempNode;
  1480.  
  1481.                             for(TempNode = (struct Node *)List->ListHeader.mlh_Head ; Continue && TempNode->ln_Succ ; TempNode = TempNode->ln_Succ)
  1482.                                 Continue = PrintFileInformation(File,ReqWindow,&Error,TempNode->ln_Name,Flags);
  1483.                         }
  1484.  
  1485.                         UnlockGenericList(List);
  1486.  
  1487.                         break;
  1488.  
  1489.                     case GLIST_WAIT:
  1490.  
  1491.                         List = GenericListTable[Index];
  1492.  
  1493.                         LockGenericList(List);
  1494.  
  1495.                         if(GenericListCount(List) > 0)
  1496.                         {
  1497.                             struct Node *TempNode;
  1498.  
  1499.                             for(TempNode = (struct Node *)List->ListHeader.mlh_Head ; Continue && TempNode->ln_Succ ; TempNode = TempNode->ln_Succ)
  1500.                                 Continue = PrintText(File,ReqWindow,&Error,"%s\n",TempNode->ln_Name);
  1501.                         }
  1502.  
  1503.                         UnlockGenericList(List);
  1504.  
  1505.                         break;
  1506.  
  1507.                     default:
  1508.  
  1509.                         switch(Mode)
  1510.                         {
  1511.                             case 0:
  1512.  
  1513.                                 Continue = PrintScreen(File,ReqWindow,&Error);
  1514.                                 break;
  1515.  
  1516.                             case 1:
  1517.  
  1518.                                 Continue = PrintClip(File,ReqWindow,&Error);
  1519.                                 break;
  1520.  
  1521.                             case 2:
  1522.  
  1523.                                 Continue = PrintBuffer(File,ReqWindow,&Error);
  1524.                                 break;
  1525.                         }
  1526.  
  1527.                         break;
  1528.                 }
  1529.  
  1530.                 FreeSysRequest(ReqWindow);
  1531.             }
  1532.  
  1533.             ReleaseWindows();
  1534.  
  1535.             Close(File);
  1536.         }
  1537.         else
  1538.             Error = IoErr();
  1539.  
  1540.         if(Error)
  1541.         {
  1542.             ResultCode[0] = RC_ERROR;
  1543.             ResultCode[1] = Error;
  1544.         }
  1545.         else
  1546.         {
  1547.             if(!Continue)
  1548.                 ResultCode[0] = RC_WARN;
  1549.         }
  1550.     }
  1551.  
  1552.     return(NULL);
  1553. }
  1554.  
  1555. STRPTR
  1556. RexxOpenRequester(struct RexxPkt *Pkt)
  1557. {
  1558.     enum    {    ARG_OPENREQUESTER_REQUESTER };
  1559.  
  1560.     LONG Index;
  1561.  
  1562.     if((Index = ToRequester(Args[ARG_OPENREQUESTER_REQUESTER])) == -1)
  1563.     {
  1564.         ResultCode[0] = RC_ERROR;
  1565.         ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  1566.     }
  1567.     else
  1568.     {
  1569.         ULONG Code;
  1570.         LONG i;
  1571.  
  1572.         switch(Index)
  1573.         {
  1574.             case REQUESTER_SERIAL:
  1575.  
  1576.                 Code = MEN_SERIAL;
  1577.                 break;
  1578.  
  1579.             case REQUESTER_MODEM:
  1580.  
  1581.                 Code = MEN_MODEM;
  1582.                 break;
  1583.  
  1584.             case REQUESTER_SCREEN:
  1585.  
  1586.                 Code = MEN_SCREEN;
  1587.                 break;
  1588.  
  1589.             case REQUESTER_TERMINAL:
  1590.  
  1591.                 Code = MEN_TERMINAL;
  1592.                 break;
  1593.  
  1594.             case REQUESTER_EMULATION:
  1595.  
  1596.                 Code = MEN_SET_EMULATION;
  1597.                 break;
  1598.  
  1599.             case REQUESTER_CLIPBOARD:
  1600.  
  1601.                 Code = MEN_CLIPBOARD;
  1602.                 break;
  1603.  
  1604.             case REQUESTER_CAPTURE:
  1605.  
  1606.                 Code = MEN_CAPTURE;
  1607.                 break;
  1608.  
  1609.             case REQUESTER_COMMANDS:
  1610.  
  1611.                 Code = MEN_COMMANDS;
  1612.                 break;
  1613.  
  1614.             case REQUESTER_MISC:
  1615.  
  1616.                 Code = MEN_MISC;
  1617.                 break;
  1618.  
  1619.             case REQUESTER_PATH:
  1620.  
  1621.                 Code = MEN_PATH;
  1622.                 break;
  1623.  
  1624.             case REQUESTER_TRANSFER:
  1625.  
  1626.                 Code = MEN_TRANSFER;
  1627.                 break;
  1628.  
  1629.             case REQUESTER_TRANSLATIONS:
  1630.  
  1631.                 Code = MEN_TRANSLATION;
  1632.                 break;
  1633.  
  1634.             case REQUESTER_FUNCTIONKEYS:
  1635.  
  1636.                 Code = MEN_MACROS;
  1637.                 break;
  1638.  
  1639.             case REQUESTER_CURSORKEYS:
  1640.  
  1641.                 Code = MEN_CURSORKEYS;
  1642.                 break;
  1643.  
  1644.             case REQUESTER_FASTMACROS:
  1645.  
  1646.                 Code = MEN_FAST_MACROS;
  1647.                 break;
  1648.  
  1649.             case REQUESTER_HOTKEYS:
  1650.  
  1651.                 Code = MEN_HOTKEYS;
  1652.                 break;
  1653.  
  1654.             case REQUESTER_SPEECH:
  1655.  
  1656.                 Code = MEN_SPEECH;
  1657.                 break;
  1658.  
  1659.             case REQUESTER_SOUND:
  1660.  
  1661.                 Code = MEN_SOUND;
  1662.                 break;
  1663.  
  1664.  
  1665.             case REQUESTER_PHONE:
  1666.  
  1667.                 Code = MEN_PHONEBOOK;
  1668.                 break;
  1669.         }
  1670.  
  1671.             /* Scan the menu list... */
  1672.  
  1673.         for(i = 0 ; TermMenu[i].nm_Type != NM_END ; i++)
  1674.         {
  1675.                 /* Did we get a valid name string? */
  1676.  
  1677.             if(TermMenu[i].nm_Label != NM_BARLABEL && (TermMenu[i].nm_Type == NM_ITEM || TermMenu[i].nm_Type == NM_SUB))
  1678.             {
  1679.                 if((ULONG)TermMenu[i].nm_UserData == Code)
  1680.                 {
  1681.                     struct DataMsg *Msg;
  1682.  
  1683.                     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  1684.                     {
  1685.                         Msg->Type = DATAMSGTYPE_MENU;
  1686.                         Msg->Size = (ULONG)TermMenu[i].nm_UserData;
  1687.                         Msg->Data = NULL;
  1688.  
  1689.                         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  1690.  
  1691.                         ResultCode[0] = RC_OK;
  1692.                     }
  1693.                     else
  1694.                         ResultCode[0] = RC_WARN;
  1695.  
  1696.                     break;
  1697.                 }
  1698.             }
  1699.         }
  1700.     }
  1701.  
  1702.     return(NULL);
  1703. }
  1704.  
  1705. STRPTR
  1706. RexxOpen(struct RexxPkt *Pkt)
  1707. {
  1708.     enum    {    ARG_OPEN_NAME,ARG_OPEN_TO };
  1709.  
  1710.     LONG Index = ToConfig(Args[ARG_OPEN_TO]);
  1711.  
  1712.     if(Index == -1 || Index > DATATYPE_PHONEBOOK)
  1713.     {
  1714.         ResultCode[0] = RC_ERROR;
  1715.         ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  1716.     }
  1717.     else
  1718.     {
  1719.         UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  1720.         STRPTR FileName;
  1721.  
  1722.         if(Args[ARG_OPEN_NAME])
  1723.             FileName = Args[ARG_OPEN_NAME];
  1724.         else
  1725.         {
  1726.             struct FileRequester *FileRequest;
  1727.             LONG TitleID;
  1728.  
  1729.             FileName = NULL;
  1730.  
  1731.             switch(Index)
  1732.             {
  1733.                 case DATATYPE_TRANSLATIONS:
  1734.  
  1735.                     TitleID = MSG_PHONEPANEL_SELECT_TRANSLATION_TXT;
  1736.                     break;
  1737.  
  1738.                 case DATATYPE_FUNCTIONKEYS:
  1739.  
  1740.                     TitleID = MSG_PHONEPANEL_SELECT_KEYBOARD_MACROS_TXT;
  1741.                     break;
  1742.  
  1743.                 case DATATYPE_CURSORKEYS:
  1744.  
  1745.                     TitleID = MSG_PHONEPANEL_SELECT_CURSOR_KEYS_TXT;
  1746.                     break;
  1747.  
  1748.                 case DATATYPE_FASTMACROS:
  1749.  
  1750.                     TitleID = MSG_PHONEPANEL_SELECT_FAST_MACROS_TXT;
  1751.                     break;
  1752.  
  1753.                 case DATATYPE_HOTKEYS:
  1754.  
  1755.                     TitleID = MSG_HOTKEYPANEL_LOAD_HOTKEYS_TXT;
  1756.                     break;
  1757.  
  1758.                 case DATATYPE_SPEECH:
  1759.  
  1760.                     TitleID = MSG_SPEECHPANEL_LOAD_SPEECH_SETTINGS_TXT;
  1761.                     break;
  1762.  
  1763.                 case DATATYPE_SOUND:
  1764.  
  1765.                     TitleID = MSG_SOUNDPANEL_LOAD_SOUNDS_TXT;
  1766.                     break;
  1767.  
  1768.                 case DATATYPE_BUFFER:
  1769.  
  1770.                     TitleID = MSG_TERMMAIN_LOAD_BUFFER_TXT;
  1771.                     break;
  1772.  
  1773.                 case DATATYPE_CONFIGURATION:
  1774.  
  1775.                     TitleID = MSG_TERMMAIN_OPEN_PREFERENCES_TXT;
  1776.                     break;
  1777.  
  1778.                 case DATATYPE_PHONEBOOK:
  1779.  
  1780.                     TitleID = MSG_PHONEPANEL_LOAD_PHONEBOOK_TXT;
  1781.                     break;
  1782.             }
  1783.  
  1784.             BlockWindows();
  1785.  
  1786.             DummyBuffer[0] = 0;
  1787.  
  1788.             if(FileRequest = OpenSingleFile(Window,LocaleString(TitleID),NULL,NULL,DummyBuffer,sizeof(DummyBuffer)))
  1789.             {
  1790.                 FreeAslRequest(FileRequest);
  1791.  
  1792.                 FileName = DummyBuffer;
  1793.             }
  1794.             else
  1795.                 ResultCode[0] = RC_WARN;
  1796.  
  1797.             ReleaseWindows();
  1798.         }
  1799.  
  1800.         if(FileName)
  1801.         {
  1802.             struct TranslationEntry    **Send,**Receive;
  1803.             BPTR SomeFile;
  1804.             BOOL Success;
  1805.  
  1806.             if(!GetFileSize(FileName))
  1807.             {
  1808.                 ResultCode[0] = RC_ERROR;
  1809.                 ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  1810.  
  1811.                 return(NULL);
  1812.             }
  1813.  
  1814.             BlockWindows();
  1815.  
  1816.             switch(Index)
  1817.             {
  1818.                 case DATATYPE_TRANSLATIONS:
  1819.  
  1820.                     Receive = NULL;
  1821.                     Success = FALSE;
  1822.  
  1823.                     if(Send = AllocTranslationTable())
  1824.                     {
  1825.                         if(Receive = AllocTranslationTable())
  1826.                         {
  1827.                             if(!(Success = LoadTranslationTables(FileName,Send,Receive)))
  1828.                             {
  1829.                                 ResultCode[0] = RC_ERROR;
  1830.                                 ResultCode[1] = IoErr();
  1831.                             }
  1832.                         }
  1833.                         else
  1834.                         {
  1835.                             ResultCode[0] = RC_ERROR;
  1836.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  1837.                         }
  1838.                     }
  1839.                     else
  1840.                     {
  1841.                         ResultCode[0] = RC_ERROR;
  1842.                         ResultCode[1] = ERROR_NO_FREE_STORE;
  1843.                     }
  1844.  
  1845.                     if(!Success)
  1846.                     {
  1847.                         if(Send)
  1848.                             FreeTranslationTable(Send);
  1849.  
  1850.                         if(Receive)
  1851.                             FreeTranslationTable(Receive);
  1852.                     }
  1853.                     else
  1854.                     {
  1855.                         strcpy(Config->TranslationFileName,FileName);
  1856.  
  1857.                         strcpy(LastTranslation,FileName);
  1858.  
  1859.                         FreeTranslationTable(SendTable);
  1860.                         FreeTranslationTable(ReceiveTable);
  1861.  
  1862.                         SendTable        = Send;
  1863.                         ReceiveTable    = Receive;
  1864.                     }
  1865.  
  1866.                     break;
  1867.  
  1868.                 case DATATYPE_FUNCTIONKEYS:
  1869.  
  1870.                     if(!LoadMacros(FileName,MacroKeys))
  1871.                     {
  1872.                         ResultCode[0] = RC_ERROR;
  1873.                         ResultCode[1] = IoErr();
  1874.                     }
  1875.                     else
  1876.                     {
  1877.                         MacroChanged = FALSE;
  1878.  
  1879.                         strcpy(LastMacros,FileName);
  1880.  
  1881.                         strcpy(Config->MacroFileName,LastMacros);
  1882.                     }
  1883.  
  1884.                     break;
  1885.  
  1886.                 case DATATYPE_CURSORKEYS:
  1887.  
  1888.                     if(!ReadIFFData(FileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  1889.                     {
  1890.                         ResultCode[0] = RC_ERROR;
  1891.                         ResultCode[1] = IoErr();
  1892.                     }
  1893.                     else
  1894.                     {
  1895.                         CursorKeysChanged = FALSE;
  1896.  
  1897.                         strcpy(LastCursorKeys,FileName);
  1898.  
  1899.                         strcpy(Config->CursorFileName,LastCursorKeys);
  1900.                     }
  1901.  
  1902.                     break;
  1903.  
  1904.                 case DATATYPE_FASTMACROS:
  1905.  
  1906.                     if(!LoadFastMacros(FileName,&FastMacroList))
  1907.                     {
  1908.                         ResultCode[0] = RC_ERROR;
  1909.                         ResultCode[1] = IoErr();
  1910.                     }
  1911.                     else
  1912.                     {
  1913.                         strcpy(Config->FastMacroFileName,FileName);
  1914.  
  1915.                         strcpy(LastFastMacros,FileName);
  1916.  
  1917.                         FastMacrosChanged = FALSE;
  1918.  
  1919.                         FastMacroCount = GetListSize(&FastMacroList);
  1920.                     }
  1921.  
  1922.                     RefreshFastWindow();
  1923.  
  1924.                     break;
  1925.  
  1926.                 case DATATYPE_HOTKEYS:
  1927.  
  1928.                     if(!LoadHotkeys(FileName,&Hotkeys))
  1929.                     {
  1930.                         ResultCode[0] = RC_ERROR;
  1931.                         ResultCode[1] = IoErr();
  1932.                     }
  1933.                     else
  1934.                     {
  1935.                         strcpy(LastKeys,FileName);
  1936.                         strcpy(Config->HotkeyFileName,LastKeys);
  1937.  
  1938.                         HotkeysChanged = FALSE;
  1939.  
  1940.                         SetupCx();
  1941.                     }
  1942.  
  1943.                     break;
  1944.  
  1945.                 case DATATYPE_SPEECH:
  1946.  
  1947.                     if(!ReadIFFData(FileName,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  1948.                     {
  1949.                         ResultCode[0] = RC_ERROR;
  1950.                         ResultCode[1] = IoErr();
  1951.                     }
  1952.                     else
  1953.                     {
  1954.                         strcpy(LastSpeech,FileName);
  1955.                         strcpy(Config->SpeechFileName,LastSpeech);
  1956.  
  1957.                         SpeechSetup();
  1958.  
  1959.                         SpeechChanged = FALSE;
  1960.                     }
  1961.  
  1962.                     break;
  1963.  
  1964.                 case DATATYPE_SOUND:
  1965.  
  1966.                     if(!ReadIFFData(FileName,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  1967.                     {
  1968.                         ResultCode[0] = RC_ERROR;
  1969.                         ResultCode[1] = IoErr();
  1970.                     }
  1971.                     else
  1972.                     {
  1973.                         strcpy(LastSound,FileName);
  1974.                         strcpy(Config->SoundFileName,LastSound);
  1975.  
  1976.                         SoundInit();
  1977.  
  1978.                         SoundChanged = FALSE;
  1979.                     }
  1980.  
  1981.                     break;
  1982.  
  1983.                 case DATATYPE_BUFFER:
  1984.  
  1985.                     if(SomeFile = Open(FileName,MODE_OLDFILE))
  1986.                     {
  1987.                         LONG Len;
  1988.  
  1989.                         LineRead(NULL,NULL,NULL);
  1990.  
  1991.                         while((Len = LineRead(SomeFile,FileName,80)) > 0)
  1992.                             CaptureParser(ParserStuff,FileName,Len,(COPTR)AddLine);
  1993.  
  1994.                         Close(SomeFile);
  1995.  
  1996.                         BufferChanged = TRUE;
  1997.                     }
  1998.                     else
  1999.                     {
  2000.                         ResultCode[0] = RC_ERROR;
  2001.                         ResultCode[1] = IoErr();
  2002.                     }
  2003.  
  2004.                     break;
  2005.  
  2006.                 case DATATYPE_CONFIGURATION:
  2007.  
  2008.                     if(ReadConfig(FileName,PrivateConfig))
  2009.                     {
  2010.                         SwapConfig(PrivateConfig,Config);
  2011.  
  2012.                         strcpy(LastConfig,FileName);
  2013.  
  2014.                         ConfigSetup();
  2015.  
  2016.                         ConfigChanged = FALSE;
  2017.                     }
  2018.                     else
  2019.                     {
  2020.                         ResultCode[0] = RC_ERROR;
  2021.                         ResultCode[1] = IoErr();
  2022.                     }
  2023.  
  2024.                     break;
  2025.  
  2026.                 case DATATYPE_PHONEBOOK:
  2027.  
  2028.                     if(GetActiveEntry(GlobalPhoneHandle))
  2029.                     {
  2030.                         ResultCode[0] = RC_ERROR;
  2031.                         ResultCode[1] = ERROR_OBJECT_IN_USE;
  2032.                     }
  2033.                     else
  2034.                     {
  2035.                         PhonebookHandle *PhoneHandle;
  2036.  
  2037.                         if(PhoneHandle = LoadPhonebook(FileName))
  2038.                         {
  2039.                             strcpy(LastPhone,FileName);
  2040.                             strcpy(Config->PhonebookFileName,LastPhone);
  2041.  
  2042.                             PhonebookChanged = FALSE;
  2043.                             RebuildMenu = TRUE;
  2044.                             ActivateJob(MainJobQueue,RebuildMenuJob);
  2045.  
  2046.                             DeletePhonebook(GlobalPhoneHandle);
  2047.                             GlobalPhoneHandle = PhoneHandle;
  2048.                         }
  2049.                         else
  2050.                         {
  2051.                             ResultCode[0] = RC_ERROR;
  2052.                             ResultCode[1] = IoErr();
  2053.                         }
  2054.                     }
  2055.  
  2056.                     break;
  2057.             }
  2058.  
  2059.             ReleaseWindows();
  2060.         }
  2061.         else
  2062.             ResultCode[0] = RC_WARN;
  2063.     }
  2064.  
  2065.     return(NULL);
  2066. }
  2067.  
  2068. STRPTR
  2069. RexxDelay(struct RexxPkt *Pkt)
  2070. {
  2071.     enum    {    ARG_DELAY_MICROSECONDS,ARG_DELAY_SECONDS,ARG_DELAY_MINUTES,ARG_DELAY_QUIET };
  2072.  
  2073.     LONG Seconds,Micros;
  2074.     ULONG Signals;
  2075.     BOOL QuietPlease;
  2076.  
  2077.     Seconds = Micros = 0;
  2078.  
  2079.     if(Args[ARG_DELAY_QUIET] || !ReadRequest || !WriteRequest)
  2080.         QuietPlease = TRUE;
  2081.     else
  2082.         QuietPlease = FALSE;
  2083.  
  2084.     if(Args[ARG_DELAY_MINUTES])
  2085.         Seconds += 60 * (*(LONG *)Args[ARG_DELAY_MINUTES]);
  2086.  
  2087.     if(Args[ARG_DELAY_SECONDS])
  2088.         Seconds += *(LONG *)Args[ARG_DELAY_SECONDS];
  2089.  
  2090.     if(Args[ARG_DELAY_MICROSECONDS])
  2091.         Micros = *(LONG *)Args[ARG_DELAY_MICROSECONDS];
  2092.  
  2093.     if(Seconds || Micros)
  2094.     {
  2095.         BOOL Done;
  2096.  
  2097.         StartTime(Seconds,Micros);
  2098.  
  2099.         BlockWindows();
  2100.  
  2101.             /* Lock the current xOFF state and clear the xOFF flag. */
  2102.  
  2103.         Lock_xOFF();
  2104.         Clear_xOFF();
  2105.  
  2106.             /* Loop until the timer has elapsed. */
  2107.  
  2108.         Done = FALSE;
  2109.  
  2110.         do
  2111.         {
  2112.                 /* Wait for something to happen. */
  2113.  
  2114.             Signals = (*SerialWaitForData)(SIG_TIMER | SIG_BREAK);
  2115.  
  2116.             if(Signals & SIG_SERIAL)
  2117.             {
  2118.                 ULONG Length;
  2119.  
  2120.                     /* Check how much data is available. */
  2121.  
  2122.                 if(Length = (*SerialGetWaiting)())
  2123.                 {
  2124.                         /* Don't read more than the buffer will hold. */
  2125.  
  2126.                     if(Length > SerialBufferSize / 2)
  2127.                         Length = SerialBufferSize / 2;
  2128.  
  2129.                         /* Read the data. */
  2130.  
  2131.                     if(Length = (*SerialRead)(ReadBuffer,Length))
  2132.                     {
  2133.                             /* Got some more data. */
  2134.  
  2135.                         BytesIn += Length;
  2136.  
  2137.                         if(Translate_CR_LF)
  2138.                             Length = (*Translate_CR_LF)(ReadBuffer,Length);
  2139.  
  2140.                         if(!QuietPlease && Length)
  2141.                             ConProcess(ReadBuffer,Length);
  2142.                     }
  2143.                 }
  2144.             }
  2145.  
  2146.             if(Signals & SIG_BREAK)
  2147.             {
  2148.                 ResultCode[0] = RC_WARN;
  2149.  
  2150.                 Done = TRUE;
  2151.             }
  2152.  
  2153.             if(Signals & SIG_TIMER)
  2154.                 Done = TRUE;
  2155.         }
  2156.         while(!Done);
  2157.  
  2158.             /* Stop the timer. */
  2159.  
  2160.         StopTime();
  2161.  
  2162.             /* Unlock the xOFF state. */
  2163.  
  2164.         Unlock_xOFF();
  2165.  
  2166.         ReleaseWindows();
  2167.     }
  2168.  
  2169.     return(NULL);
  2170. }
  2171.  
  2172. STRPTR
  2173. RexxCapture(struct RexxPkt *Pkt)
  2174. {
  2175.     enum    {    ARG_CAPTURE_TO,ARG_CAPTURE_NAME,ARG_OVERWRITE,ARG_APPEND,ARG_SKIP };
  2176.  
  2177.     if(!Stricmp(Args[ARG_CAPTURE_TO],"PRINTER"))
  2178.     {
  2179.         if(!PrinterCapture)
  2180.             OpenPrinterCapture(FALSE);
  2181.     }
  2182.     else
  2183.     {
  2184.         if(!Stricmp(Args[ARG_CAPTURE_TO],"FILE"))
  2185.         {
  2186.             if(FileCapture)
  2187.             {
  2188.                 ResultCode[0] = RC_ERROR;
  2189.                 ResultCode[1] = ERROR_OBJECT_IN_USE;
  2190.             }
  2191.             else
  2192.             {
  2193.                 if(Args[ARG_CAPTURE_NAME])
  2194.                 {
  2195.                     if(FileCapture = BufferOpen(Args[ARG_CAPTURE_NAME],"a"))
  2196.                         strcpy(CaptureName,Args[ARG_CAPTURE_NAME]);
  2197.                     else
  2198.                     {
  2199.                         ResultCode[0] = RC_ERROR;
  2200.                         ResultCode[1] = IoErr();
  2201.                     }
  2202.                 }
  2203.                 else
  2204.                 {
  2205.                     UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  2206.                     struct FileRequester *FileRequest;
  2207.  
  2208.                     if(!CaptureName[0])
  2209.                     {
  2210.                         strcpy(CaptureName,Config->CaptureConfig->CapturePath);
  2211.  
  2212.                         if(!AddPart(CaptureName,LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT),sizeof(DummyBuffer)))
  2213.                             CaptureName[0] = 0;
  2214.                     }
  2215.  
  2216.                     strcpy(DummyBuffer,CaptureName);
  2217.  
  2218.                     BlockWindows();
  2219.  
  2220.                     if(FileRequest = SaveFile(Window,LocaleString(MSG_TERMMAIN_CAPTURE_TO_DISK_TXT),LocaleString(MSG_GLOBAL_OPEN_TXT),NULL,DummyBuffer,sizeof(DummyBuffer)))
  2221.                     {
  2222.                         BOOL Continue;
  2223.  
  2224.                         if(GetFileSize(DummyBuffer))
  2225.                         {
  2226.                             Continue = TRUE;
  2227.  
  2228.                             if(!Args[ARG_OVERWRITE] && ! Args[ARG_APPEND] && ! Args[ARG_SKIP])
  2229.                             {
  2230.                                 switch(ShowRequest(Window,LocaleString(MSG_GLOBAL_FILE_ALREADY_EXISTS_TXT),LocaleString(MSG_GLOBAL_CREATE_APPEND_CANCEL_TXT),DummyBuffer))
  2231.                                 {
  2232.                                     case 0:
  2233.  
  2234.                                         ResultCode[0] = RC_WARN;
  2235.                                         Continue = FALSE;
  2236.                                         break;
  2237.  
  2238.                                     case 1:
  2239.  
  2240.                                         FileCapture = BufferOpen(DummyBuffer,"w");
  2241.                                         break;
  2242.  
  2243.                                     case 2:
  2244.  
  2245.                                         FileCapture = BufferOpen(DummyBuffer,"a");
  2246.                                         break;
  2247.                                 }
  2248.                             }
  2249.                             else
  2250.                             {
  2251.                                 STRPTR Mode;
  2252.  
  2253.                                 if(Args[ARG_OVERWRITE])
  2254.                                     Mode = "w";
  2255.                                 else if(Args[ARG_APPEND])
  2256.                                     Mode = "a";
  2257.                                 else
  2258.                                     Mode = NULL;
  2259.  
  2260.                                 if(Mode)
  2261.                                     FileCapture = BufferOpen(DummyBuffer,Mode);
  2262.                                 else
  2263.                                 {
  2264.                                     ResultCode[0] = RC_WARN;
  2265.                                     Continue = FALSE;
  2266.                                 }
  2267.                             }
  2268.                         }
  2269.                         else
  2270.                         {
  2271.                             Continue = TRUE;
  2272.  
  2273.                             FileCapture = BufferOpen(DummyBuffer,"w");
  2274.                         }
  2275.  
  2276.                         if(Continue)
  2277.                         {
  2278.                             if(!FileCapture)
  2279.                             {
  2280.                                 ShowRequest(Window,LocaleString(MSG_GLOBAL_ERROR_OPENING_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  2281.  
  2282.                                 ResultCode[0] = RC_ERROR;
  2283.                                 ResultCode[1] = IoErr();
  2284.                             }
  2285.                             else
  2286.                             {
  2287.                                 strcpy(CaptureName,DummyBuffer);
  2288.  
  2289.                                 CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  2290.                             }
  2291.                         }
  2292.  
  2293.                         FreeAslRequest(FileRequest);
  2294.                     }
  2295.  
  2296.                     ReleaseWindows();
  2297.                 }
  2298.             }
  2299.         }
  2300.         else
  2301.         {
  2302.             ResultCode[0] = RC_ERROR;
  2303.             ResultCode[1] = ERROR_REQUIRED_ARG_MISSING;
  2304.         }
  2305.     }
  2306.  
  2307.     ConOutputUpdate();
  2308.  
  2309.     CheckItem(MEN_CAPTURE_TO_FILE,        FileCapture != NULL);
  2310.     CheckItem(MEN_CAPTURE_TO_PRINTER,    PrinterCapture != NULL);
  2311.  
  2312.     return(NULL);
  2313. }
  2314.  
  2315. STRPTR
  2316. RexxAdd(struct RexxPkt *Pkt)
  2317. {
  2318.     enum    {    ARG_ADD_FROM,ARG_ADD_BEFORE,ARG_ADD_AFTER,ARG_ADD_RESPONSE,
  2319.                 ARG_ADD_COMMAND,ARG_ADD_PHONEENTRY,ARG_ADD_NAME
  2320.             };
  2321.  
  2322.     LONG ListIndex;
  2323.  
  2324.     if((ListIndex = ToList(Args[ARG_ADD_FROM])) != -1)
  2325.     {
  2326.         struct GenericList *List = GenericListTable[ListIndex];
  2327.         LONG AddMode;
  2328.  
  2329.         if(Args[ARG_ADD_BEFORE])
  2330.             AddMode = ADD_GLIST_BEFORE;
  2331.         else
  2332.         {
  2333.             if(Args[ARG_ADD_AFTER])
  2334.                 AddMode = ADD_GLIST_BEHIND;
  2335.             else
  2336.                 AddMode = ADD_GLIST_BOTTOM;
  2337.         }
  2338.  
  2339.         if(ListIndex == GLIST_DIAL)
  2340.         {
  2341.             if(Args[ARG_ADD_PHONEENTRY])
  2342.             {
  2343.                 if(!IsNumeric(Args[ARG_ADD_PHONEENTRY]))
  2344.                 {
  2345.                     STRPTR Buffer;
  2346.  
  2347.                     if(Buffer = CreateMatchBuffer(Args[ARG_ADD_PHONEENTRY]))
  2348.                     {
  2349.                         struct GenericDialNode *Node;
  2350.                         BOOL GotIt = FALSE;
  2351.                         LONG i;
  2352.  
  2353.                         for(i = 0 ; i < GlobalPhoneHandle->NumPhoneEntries ; i++)
  2354.                         {
  2355.                             if(MatchBuffer(Buffer,GlobalPhoneHandle->Phonebook[i]->Header->Name))
  2356.                             {
  2357.                                 if(Node = (struct GenericDialNode *)CreateGenericListNode(sizeof(struct GenericDialNode),GlobalPhoneHandle->Phonebook[i]->Header->Name))
  2358.                                 {
  2359.                                     Node->Number = NULL;
  2360.                                     Node->Index = -1;
  2361.  
  2362.                                     AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2363.  
  2364.                                     GotIt = TRUE;
  2365.                                 }
  2366.                                 else
  2367.                                 {
  2368.                                     ResultCode[0] = RC_ERROR;
  2369.                                     ResultCode[1] = ERROR_NO_FREE_STORE;
  2370.  
  2371.                                     break;
  2372.                                 }
  2373.                             }
  2374.                         }
  2375.  
  2376.                         if(!GotIt && ResultCode[0] != RC_ERROR)
  2377.                         {
  2378.                             ResultCode[0] = RC_ERROR;
  2379.                             ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  2380.                         }
  2381.  
  2382.                         DeleteMatchBuffer(Buffer);
  2383.                     }
  2384.                     else
  2385.                     {
  2386.                         ResultCode[0] = RC_ERROR;
  2387.                         ResultCode[1] = ERROR_NO_FREE_STORE;
  2388.                     }
  2389.                 }
  2390.                 else
  2391.                 {
  2392.                     LONG Index = Atol(Args[ARG_ADD_PHONEENTRY]);
  2393.  
  2394.                     if(Index < 0 || Index > GlobalPhoneHandle->NumPhoneEntries)
  2395.                     {
  2396.                         ResultCode[0] = RC_ERROR;
  2397.                         ResultCode[1] = TERMERROR_INDEX_OUT_OF_RANGE;
  2398.                     }
  2399.                     else
  2400.                     {
  2401.                         struct GenericDialNode *Node;
  2402.  
  2403.                         if(Node = (struct GenericDialNode *)CreateGenericListNode(sizeof(struct GenericDialNode),GlobalPhoneHandle->Phonebook[Index]->Header->Name))
  2404.                         {
  2405.                             Node->Number = NULL;
  2406.                             Node->Index = Index;
  2407.  
  2408.                             AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2409.                         }
  2410.                         else
  2411.                         {
  2412.                             ResultCode[0] = RC_ERROR;
  2413.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  2414.                         }
  2415.                     }
  2416.                 }
  2417.             }
  2418.             else
  2419.             {
  2420.                 if(Args[ARG_ADD_NAME])
  2421.                 {
  2422.                     struct GenericDialNode *Node;
  2423.  
  2424.                     if(Node = (struct GenericDialNode *)CreateGenericListNode(sizeof(struct GenericDialNode),Args[ARG_ADD_NAME]))
  2425.                     {
  2426.                         Node->Number = Node->Node.ln_Name;
  2427.                         Node->Index = -1;
  2428.  
  2429.                         AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2430.                     }
  2431.                     else
  2432.                     {
  2433.                         ResultCode[0] = RC_ERROR;
  2434.                         ResultCode[1] = ERROR_NO_FREE_STORE;
  2435.                     }
  2436.                 }
  2437.             }
  2438.         }
  2439.         else
  2440.         {
  2441.             if(ListIndex == GLIST_WAIT)
  2442.             {
  2443.                 STRPTR    Response;
  2444.                 LONG    ResponseLen;
  2445.  
  2446.                 if(Args[ARG_ADD_RESPONSE])
  2447.                 {
  2448.                     Response    = Args[ARG_ADD_RESPONSE];
  2449.                     ResponseLen    = strlen(Response);
  2450.                 }
  2451.                 else
  2452.                 {
  2453.                     Response    = NULL;
  2454.                     ResponseLen    = 0;
  2455.                 }
  2456.  
  2457.                 if(Args[ARG_ADD_NAME])
  2458.                 {
  2459.                     struct WaitNode *Node;
  2460.  
  2461.                     if(Node = (struct WaitNode *)CreateGenericListNode(sizeof(struct WaitNode) + ResponseLen + 1,Args[ARG_ADD_NAME]))
  2462.                     {
  2463.                         LONG i,Len;
  2464.  
  2465.                         Len = TranslateString(Node->Node.ln_Name,Node->Node.ln_Name);
  2466.  
  2467.                         Node->Node.ln_Name[Len] = 0;
  2468.  
  2469.                         for(i = 0 ; i < Len ; i++)
  2470.                             Node->Node.ln_Name[i] = ToUpper(Node->Node.ln_Name[i]);
  2471.  
  2472.                         if(Response && ResponseLen)
  2473.                         {
  2474.                             Node->Response = &Node->Node.ln_Name[Len + 1];
  2475.  
  2476.                             strcpy(Node->Response,Response);
  2477.  
  2478.                             Node->ResponseLen = TranslateString(Node->Response,Node->Response);
  2479.                         }
  2480.                         else
  2481.                             Node->ResponseLen = 0;
  2482.  
  2483.                         AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2484.                     }
  2485.                     else
  2486.                     {
  2487.                         ResultCode[0] = RC_ERROR;
  2488.                         ResultCode[1] = ERROR_NO_FREE_STORE;
  2489.                     }
  2490.                 }
  2491.                 else
  2492.                 {
  2493.                     ResultCode[0] = RC_ERROR;
  2494.                     ResultCode[1] = ERROR_REQUIRED_ARG_MISSING;
  2495.                 }
  2496.             }
  2497.             else
  2498.             {
  2499.                 if(ListIndex == GLIST_TRAP)
  2500.                 {
  2501.                     if(!Args[ARG_ADD_NAME] || !Args[ARG_ADD_COMMAND])
  2502.                     {
  2503.                         struct TrapNode    *Node;
  2504.                         UBYTE LocalBuffer[MAX_FILENAME_LENGTH];
  2505.                         LONG NameLen;
  2506.  
  2507.                         if(strlen(Args[ARG_ADD_NAME]) > sizeof(LocalBuffer) - 1)
  2508.                             Args[ARG_ADD_NAME][sizeof(LocalBuffer) - 1] = 0;
  2509.  
  2510.                         NameLen = TranslateString(Args[ARG_ADD_NAME],LocalBuffer);
  2511.  
  2512.                         if(Node = (struct TrapNode *)AllocVecPooled(sizeof(struct TrapNode) + strlen(Args[ARG_ADD_NAME]) + 1 + NameLen + strlen(Args[ARG_ADD_COMMAND]) + 1,MEMF_ANY))
  2513.                         {
  2514.                             STRPTR String = Node->Node.ln_Name = (STRPTR)(Node + 1);
  2515.  
  2516.                             strcpy(String,Args[ARG_ADD_NAME]);
  2517.  
  2518.                             String += strlen(String) + 1;
  2519.  
  2520.                             Node->Sequence = String;
  2521.  
  2522.                             CopyMem(LocalBuffer,String,NameLen);
  2523.  
  2524.                             String += NameLen;
  2525.  
  2526.                             Node->Command = String;
  2527.  
  2528.                             strcpy(String,Args[ARG_ADD_COMMAND]);
  2529.  
  2530.                             Node->SequenceLen = NameLen;
  2531.                             Node->Count = 0;
  2532.  
  2533.                             AddGenericListNode(List,(struct Node *)Node,AddMode,TRUE);
  2534.                         }
  2535.                         else
  2536.                         {
  2537.                             ResultCode[0] = RC_ERROR;
  2538.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  2539.                         }
  2540.                     }
  2541.                     else
  2542.                     {
  2543.                         ResultCode[0] = RC_ERROR;
  2544.                         ResultCode[1] = ERROR_REQUIRED_ARG_MISSING;
  2545.                     }
  2546.                 }
  2547.                 else
  2548.                 {
  2549.                     if(Args[ARG_ADD_NAME])
  2550.                     {
  2551.                         struct Node *Node;
  2552.  
  2553.                         if(Node = CreateGenericListNode(sizeof(struct DialNode),Args[ARG_ADD_NAME]))
  2554.                             AddGenericListNode(List,Node,AddMode,TRUE);
  2555.                         else
  2556.                         {
  2557.                             ResultCode[0] = RC_ERROR;
  2558.                             ResultCode[1] = ERROR_NO_FREE_STORE;
  2559.                         }
  2560.                     }
  2561.                     else
  2562.                     {
  2563.                         ResultCode[0] = RC_ERROR;
  2564.                         ResultCode[1] = TERMERROR_WRONG_LIST;
  2565.                     }
  2566.                 }
  2567.             }
  2568.         }
  2569.     }
  2570.     else
  2571.     {
  2572.         ResultCode[0] = RC_ERROR;
  2573.         ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  2574.     }
  2575.  
  2576.     return(NULL);
  2577. }
  2578.  
  2579. STRPTR
  2580. RexxActivate(struct RexxPkt *UnusedPkt)
  2581. {
  2582.     if(Window)
  2583.         BumpWindow(Window);
  2584.     else
  2585.         Signal((struct Task *)ThisProcess,SIGBREAKF_CTRL_F);
  2586.  
  2587.     return(NULL);
  2588. }
  2589.  
  2590. STRPTR
  2591. RexxBaud(struct RexxPkt *Pkt)
  2592. {
  2593.     enum    {    ARG_BAUD_RATE };
  2594.  
  2595.     LONG Rate = *(LONG *)Args[ARG_BAUD_RATE],Min = MILLION,Diff,Index;
  2596.     UBYTE Number[10];
  2597.     LONG i;
  2598.  
  2599.     for(i = 0 ; i < NumBaudRates ; i++)
  2600.     {
  2601.         Diff = Rate - BaudRates[i];
  2602.  
  2603.         if(Diff >= 0 && Diff < Min)
  2604.         {
  2605.             Min        = Diff;
  2606.             Index    = i;
  2607.         }
  2608.     }
  2609.  
  2610.     LimitedSPrintf(sizeof(Number),Number,"%ld");
  2611.  
  2612.     if(BaudRates[Index] != Config->SerialConfig->BaudRate)
  2613.     {
  2614.         Config->SerialConfig->BaudRate = BaudRates[Index];
  2615.  
  2616.         ConfigChanged = TRUE;
  2617.  
  2618.         UpdateRequired = TRUE;
  2619.     }
  2620.  
  2621.     return(CreateArgstring(Number,strlen(Number)));
  2622. }
  2623.  
  2624. STRPTR
  2625. RexxBeepScreen(struct RexxPkt *UnusedPkt)
  2626. {
  2627.     BellSignal();
  2628.  
  2629.     return(NULL);
  2630. }
  2631.  
  2632. STRPTR
  2633. RexxCallMenu(struct RexxPkt *Pkt)
  2634. {
  2635.     enum    {    ARG_CALLMENU_TITLE };
  2636.  
  2637.     STRPTR Buffer;
  2638.  
  2639.     if(Buffer = CreateMatchBuffer(Args[ARG_CALLMENU_TITLE]))
  2640.     {
  2641.         LONG i;
  2642.  
  2643.         ResultCode[0] = RC_WARN;
  2644.  
  2645.             /* Scan the menu list... */
  2646.  
  2647.         for(i = 0 ; TermMenu[i].nm_Type != NM_END ; i++)
  2648.         {
  2649.                 /* Did we get a valid name string? */
  2650.  
  2651.             if(TermMenu[i].nm_Label != NM_BARLABEL && (TermMenu[i].nm_Type == NM_ITEM || TermMenu[i].nm_Type == NM_SUB))
  2652.             {
  2653.                     /* Does the name match our template? */
  2654.  
  2655.                 if(MatchBuffer(Buffer,TermMenu[i].nm_Label))
  2656.                 {
  2657.                     struct DataMsg *Msg;
  2658.  
  2659.                     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  2660.                     {
  2661.                         Msg->Type = DATAMSGTYPE_MENU;
  2662.                         Msg->Size = (ULONG)TermMenu[i].nm_UserData;
  2663.                         Msg->Data = NULL;
  2664.  
  2665.                         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  2666.  
  2667.                         ResultCode[0] = RC_OK;
  2668.                     }
  2669.                     else
  2670.                         ResultCode[0] = RC_WARN;
  2671.  
  2672.                     break;
  2673.                 }
  2674.             }
  2675.         }
  2676.  
  2677.         DeleteMatchBuffer(Buffer);
  2678.     }
  2679.     else
  2680.     {
  2681.         ResultCode[0] = RC_ERROR;
  2682.         ResultCode[1] = ERROR_NO_FREE_STORE;
  2683.     }
  2684.  
  2685.     return(NULL);
  2686. }
  2687.  
  2688. STRPTR
  2689. RexxClear(struct RexxPkt *Pkt)
  2690. {
  2691.     enum    {    ARG_CLEAR_FROM,ARG_CLEAR_FORCE };
  2692.  
  2693.     if(!Stricmp(Args[ARG_CLEAR_FROM],"BUFFER"))
  2694.     {
  2695.         if(Lines)
  2696.         {
  2697.             if(Args[ARG_CLEAR_FORCE])
  2698.             {
  2699.                 FreeBuffer();
  2700.  
  2701.                 TerminateBuffer();
  2702.             }
  2703.             else
  2704.             {
  2705.                 BlockWindows();
  2706.  
  2707.                 if(ShowRequest(Window,LocaleString(MSG_TERMMAIN_BUFFER_STILL_HOLDS_LINES_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT),Lines))
  2708.                 {
  2709.                     FreeBuffer();
  2710.  
  2711.                     TerminateBuffer();
  2712.                 }
  2713.                 else
  2714.                     ResultCode[0] = RC_WARN;
  2715.  
  2716.                 ReleaseWindows();
  2717.             }
  2718.         }
  2719.     }
  2720.     else
  2721.     {
  2722.         LONG ListIndex;
  2723.  
  2724.         if((ListIndex = ToList(Args[ARG_CLEAR_FROM])) != -1)
  2725.             ClearGenericList(GenericListTable[ListIndex],TRUE);
  2726.         else
  2727.         {
  2728.             ResultCode[0] = RC_ERROR;
  2729.             ResultCode[1] = TERMERROR_UNKNOWN_LIST;
  2730.         }
  2731.     }
  2732.  
  2733.     return(NULL);
  2734. }
  2735.  
  2736. STRPTR
  2737. RexxClearScreen(struct RexxPkt *UnusedPkt)
  2738. {
  2739.     ConClear();
  2740.  
  2741.     return(NULL);
  2742. }
  2743.  
  2744. STRPTR
  2745. RexxClose(struct RexxPkt *Pkt)
  2746. {
  2747.     enum    {    ARG_CLOSE_FROM };
  2748.  
  2749.     STATIC STRPTR ValidArgs[3] =
  2750.     {
  2751.         "PRINTER",
  2752.         "FILE",
  2753.         "ALL"
  2754.     };
  2755.  
  2756.     LONG i;
  2757.  
  2758.     for(i = 0 ; i < 3 ; i++)
  2759.     {
  2760.         if(!Stricmp(Args[ARG_CLOSE_FROM],ValidArgs[i]))
  2761.         {
  2762.             if(i == 0 || i == 2)
  2763.             {
  2764.                 if(PrinterCapture)
  2765.                     ClosePrinterCapture(TRUE);
  2766.             }
  2767.  
  2768.             if(i == 1 || i == 2)
  2769.             {
  2770.                 if(FileCapture)
  2771.                 {
  2772.                     BufferClose(FileCapture);
  2773.  
  2774.                     CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  2775.  
  2776.                     FileCapture = NULL;
  2777.  
  2778.                     if(!GetFileSize(CaptureName))
  2779.                         DeleteFile(CaptureName);
  2780.                     else
  2781.                     {
  2782.                         AddProtection(CaptureName,FIBF_EXECUTE);
  2783.  
  2784.                         if(Config->MiscConfig->CreateIcons)
  2785.                             AddIcon(CaptureName,FILETYPE_TEXT,TRUE);
  2786.                     }
  2787.  
  2788.                     ConOutputUpdate();
  2789.                 }
  2790.             }
  2791.  
  2792.             return(NULL);
  2793.         }
  2794.     }
  2795.  
  2796.     ResultCode[0] = RC_ERROR;
  2797.     ResultCode[1] = ERROR_TOO_MANY_ARGS;
  2798.  
  2799.     return(NULL);
  2800. }
  2801.  
  2802. STRPTR
  2803. RexxCloseDevice(struct RexxPkt *UnusedPkt)
  2804. {
  2805.     ClearSerial();
  2806.  
  2807.     DeleteSerial();
  2808.  
  2809.     return(NULL);
  2810. }
  2811.  
  2812. STRPTR
  2813. RexxCloseRequester(struct RexxPkt *Pkt)
  2814. {
  2815.     if(ThisProcess)
  2816.         Signal((struct Task *)ThisProcess,SIG_BREAK);
  2817.     else
  2818.         ResultCode[0] = RC_WARN;
  2819.  
  2820.     return(NULL);
  2821. }
  2822.  
  2823. STRPTR
  2824. RexxDeactivate(struct RexxPkt *UnusedPkt)
  2825. {
  2826.     Forbid();
  2827.  
  2828.     if(Window)
  2829.         ActivateJob(MainJobQueue,IconifyJob);
  2830.  
  2831.     Permit();
  2832.  
  2833.     return(NULL);
  2834. }
  2835.  
  2836. STATIC VOID
  2837. RexxDialDestructor(struct MsgItem *Item)
  2838. {
  2839.     if(((struct DataDialMsg *)Item)->DialMsg)
  2840.     {
  2841.         ((struct DataDialMsg *)Item)->DialMsg->rm_Result1 = RC_WARN;
  2842.         ((struct DataDialMsg *)Item)->DialMsg->rm_Result2 = 0;
  2843.  
  2844.         ReplyMsg((struct Message *)((struct DataDialMsg *)Item)->DialMsg);
  2845.     }
  2846.  
  2847.     DeleteList(((struct DataDialMsg *)Item)->DialList);
  2848.  
  2849.     FreeVecPooled(Item);
  2850. }
  2851.  
  2852. STRPTR
  2853. RexxDial(struct RexxPkt *Pkt)
  2854. {
  2855.     enum    {    ARG_SYNC,ARG_DIAL_NUM };
  2856.  
  2857.     struct DataDialMsg *Msg;
  2858.     struct List *DialList;
  2859.  
  2860.     if(!(Msg = (struct DataDialMsg *)CreateMsgItem(sizeof(struct DataDialMsg))))
  2861.     {
  2862.         ResultCode[0] = RC_ERROR;
  2863.         ResultCode[1] = ERROR_NO_FREE_STORE;
  2864.  
  2865.         return(NULL);
  2866.     }
  2867.  
  2868.     if(Args[ARG_DIAL_NUM])
  2869.     {
  2870.         if(DialList = CreateList())
  2871.         {
  2872.             struct GenericDialNode *Node;
  2873.             LONG Len;
  2874.  
  2875.             Len = strlen(Args[ARG_DIAL_NUM]);
  2876.  
  2877.             if(Node = (struct GenericDialNode *)AllocVecPooled(sizeof(struct DialNode) + Len + 1,MEMF_ANY | MEMF_CLEAR))
  2878.             {
  2879.                 Node->Node.ln_Name = (STRPTR)(Node + 1);
  2880.  
  2881.                 strcpy(Node->Node.ln_Name,Args[ARG_DIAL_NUM]);
  2882.  
  2883.                 Node->Number = Node->Node.ln_Name;
  2884.                 Node->Index = -1;
  2885.  
  2886.                 AddTail(DialList,(struct Node *)Node);
  2887.             }
  2888.             else
  2889.             {
  2890.                 DeleteMsgItem((struct MsgItem *)Msg);
  2891.                 FreeVecPooled(DialList);
  2892.  
  2893.                 ResultCode[0] = RC_ERROR;
  2894.                 ResultCode[1] = ERROR_NO_FREE_STORE;
  2895.  
  2896.                 return(NULL);
  2897.             }
  2898.         }
  2899.         else
  2900.         {
  2901.             DeleteMsgItem((struct MsgItem *)Msg);
  2902.             ResultCode[0] = RC_ERROR;
  2903.             ResultCode[1] = ERROR_NO_FREE_STORE;
  2904.  
  2905.             return(NULL);
  2906.         }
  2907.     }
  2908.     else
  2909.     {
  2910.         if(GenericListCount(GenericListTable[GLIST_DIAL]) > 0)
  2911.         {
  2912.             if(DialList = CreateList())
  2913.             {
  2914.                 struct Node *Node;
  2915.  
  2916.                 while(Node = RemoveFirstGenericListNode(GenericListTable[GLIST_DIAL]))
  2917.                     AddTail(DialList,Node);
  2918.             }
  2919.             else
  2920.             {
  2921.                 DeleteMsgItem((struct MsgItem *)Msg);
  2922.  
  2923.                 ResultCode[0] = RC_ERROR;
  2924.                 ResultCode[1] = ERROR_NO_FREE_STORE;
  2925.  
  2926.                 return(NULL);
  2927.             }
  2928.         }
  2929.         else
  2930.             DialList = NULL;
  2931.     }
  2932.  
  2933.     if(DialList)
  2934.     {
  2935.         if(Args[ARG_SYNC])
  2936.         {
  2937.             Msg->DialMsg = Pkt->RexxMsg;
  2938.  
  2939.             Pkt->RexxMsg = NULL;
  2940.         }
  2941.         else
  2942.             Msg->DialMsg = NULL;
  2943.  
  2944.         InitMsgItem(Msg,RexxDialDestructor);
  2945.  
  2946.         Msg->Data.Type = DATAMSGTYPE_DIAL;
  2947.         Msg->DialList = DialList;
  2948.  
  2949.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  2950.     }
  2951.     else
  2952.         DeleteMsgItem((struct MsgItem *)Msg);
  2953.  
  2954.     return(NULL);
  2955. }
  2956.  
  2957. STRPTR
  2958. RexxDuplex(struct RexxPkt *Pkt)
  2959. {
  2960.     enum    {    ARG_DUPLEX_FULL,ARG_DUPLEX_HALF };
  2961.  
  2962.     LONG OldMode;
  2963.     LONG Mode;
  2964.  
  2965.     if(Args[ARG_DUPLEX_FULL])
  2966.         Mode = DUPLEX_FULL;
  2967.  
  2968.     if(Args[ARG_DUPLEX_HALF])
  2969.         Mode = DUPLEX_HALF;
  2970.  
  2971.     OldMode = Config->SerialConfig->Duplex;
  2972.  
  2973.     if(Config->SerialConfig->Duplex != Mode)
  2974.     {
  2975.         Config->SerialConfig->Duplex = Mode;
  2976.  
  2977.         UpdateRequired = TRUE;
  2978.  
  2979.         ConfigChanged = TRUE;
  2980.     }
  2981.  
  2982.     return(CreateArgstring(DuplexMappings[OldMode],strlen(DuplexMappings[OldMode])));
  2983. }
  2984.  
  2985. STRPTR
  2986. RexxFault(struct RexxPkt *Pkt)
  2987. {
  2988.     enum    {    ARG_FAULT_CODE };
  2989.  
  2990.     LONG Code = *(LONG *)Args[ARG_FAULT_CODE];
  2991.     UBYTE RexxResultString[MAX_FILENAME_LENGTH];
  2992.     STRPTR Result;
  2993.  
  2994.     if(Code >= ERR10_001 && Code <= ERR10_048)
  2995.         Result = LocaleString(MSG_AREXX_SYSERR10_001_TXT + Code - ERR10_001);
  2996.     else
  2997.     {
  2998.         if(Code >= TERMERROR_NO_DATA_TO_PROCESS && Code <= TERMERROR_WRONG_LIST)
  2999.             Result = LocaleString(MSG_AREXX_HOSTERR_000_TXT + Code - TERMERROR_NO_DATA_TO_PROCESS);
  3000.         else
  3001.         {
  3002.             Fault(Code,NULL,RexxResultString,sizeof(RexxResultString));
  3003.  
  3004.             Result = RexxResultString;
  3005.         }
  3006.     }
  3007.  
  3008.     return(CreateResult(Result,ResultCode));
  3009. }
  3010.  
  3011. STRPTR
  3012. RexxGetClip(struct RexxPkt *Pkt)
  3013. {
  3014.     enum    {    ARG_GETCLIP_UNIT };
  3015.  
  3016.     struct IFFHandle *Handle;
  3017.     STRPTR ResultBuffer;
  3018.     LONG Unit;
  3019.     LONG Error;
  3020.  
  3021.     if(Args[ARG_GETCLIP_UNIT])
  3022.         Unit = *(LONG *)Args[ARG_GETCLIP_UNIT];
  3023.     else
  3024.         Unit = Config->ClipConfig->ClipboardUnit;
  3025.  
  3026.     ResultBuffer = NULL;
  3027.  
  3028.     if(Handle = OpenIFFClip(Unit,MODE_OLDFILE))
  3029.     {
  3030.         if(!(Error = StopChunk(Handle,ID_FTXT,ID_CHRS)))
  3031.         {
  3032.             if(!ParseIFF(Handle,IFFPARSE_SCAN))
  3033.             {
  3034.                 struct ContextNode *ContextNode;
  3035.  
  3036.                 ContextNode = CurrentChunk(Handle);
  3037.  
  3038.                 if(ContextNode->cn_Type == ID_FTXT && ContextNode->cn_Size > 0)
  3039.                 {
  3040.                     STRPTR Result;
  3041.  
  3042.                     if(Result = (STRPTR)AllocVecPooled(ContextNode->cn_Size,MEMF_ANY))
  3043.                     {
  3044.                         if(ReadChunkBytes(Handle,Result,ContextNode->cn_Size) == ContextNode->cn_Size)
  3045.                             ResultBuffer = CreateArgstring(Result,ContextNode->cn_Size);
  3046.  
  3047.                         FreeVecPooled(Result);
  3048.                     }
  3049.                     else
  3050.                         Error = ERROR_NO_FREE_STORE;
  3051.                 }
  3052.                 else
  3053.                     ResultCode[0] = RC_WARN;
  3054.             }
  3055.             else
  3056.                 Error = ERROR_OBJECT_NOT_FOUND;
  3057.         }
  3058.  
  3059.         CloseIFFClip(Handle);
  3060.     }
  3061.     else
  3062.         Error = IoErr();
  3063.  
  3064.     if(Error)
  3065.     {
  3066.         ResultCode[0] = RC_ERROR;
  3067.         ResultCode[1] = Error;
  3068.     }
  3069.  
  3070.     return(ResultBuffer);
  3071. }
  3072.  
  3073. STRPTR
  3074. RexxGoOnline(struct RexxPkt *Pkt)
  3075. {
  3076.     struct DataMsg *Msg;
  3077.  
  3078.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3079.     {
  3080.         Msg->Type = DATAMSGTYPE_GOONLINE;
  3081.  
  3082.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3083.     }
  3084.     else
  3085.         ResultCode[0] = RC_WARN;
  3086.  
  3087.     return(NULL);
  3088. }
  3089.  
  3090. STRPTR
  3091. RexxHangup(struct RexxPkt *Pkt)
  3092. {
  3093.     struct DataMsg *Msg;
  3094.  
  3095.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3096.     {
  3097.         Msg->Type = DATAMSGTYPE_HANGUP;
  3098.         Msg->Data = (UBYTE *)Pkt->RexxMsg;
  3099.  
  3100.         Pkt->RexxMsg = NULL;
  3101.  
  3102.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3103.     }
  3104.     else
  3105.         ResultCode[0] = RC_WARN;
  3106.  
  3107.     return(NULL);
  3108. }
  3109.  
  3110. STRPTR
  3111. RexxHelp(struct RexxPkt *Pkt)
  3112. {
  3113.     enum    {    ARG_HELP_COMMAND,ARG_HELP_PROMPT };
  3114.  
  3115.     if(Args[ARG_HELP_PROMPT])
  3116.         GuideSetup();
  3117.     else
  3118.     {
  3119.         LONG i;
  3120.  
  3121.         for(i = 0 ; i < CommandTableSize ; i++)
  3122.         {
  3123.             if(!Stricmp(Args[ARG_HELP_COMMAND],CommandTable[i].Name))
  3124.             {
  3125.                 if(CommandTable[i].Arguments)
  3126.                     return(CreateResult(CommandTable[i].Arguments,ResultCode));
  3127.                 else
  3128.                     return(CreateResult(",",ResultCode));
  3129.             }
  3130.         }
  3131.  
  3132.         ResultCode[0] = RC_ERROR;
  3133.         ResultCode[1] = ERROR_OBJECT_NOT_FOUND;
  3134.     }
  3135.  
  3136.     return(NULL);
  3137. }
  3138.  
  3139. STRPTR
  3140. RexxOpenDevice(struct RexxPkt *Pkt)
  3141. {
  3142.     enum    {    ARG_OPENDEVICE_NAME,ARG_OPENDEVICE_UNIT };
  3143.  
  3144.     if(ReadRequest)
  3145.     {
  3146.         ResultCode[0] = RC_ERROR;
  3147.         ResultCode[1] = TERMERROR_DEVICE_DRIVER_STILL_OPEN;
  3148.  
  3149.         return(NULL);
  3150.     }
  3151.     else
  3152.     {
  3153.         UBYTE Result[MAX_FILENAME_LENGTH+10];
  3154.  
  3155.         LimitedSPrintf(sizeof(Result),"\"%s\" %ld",Config->SerialConfig->SerialDevice,Config->SerialConfig->UnitNumber);
  3156.  
  3157.         if(Args[ARG_OPENDEVICE_NAME])
  3158.         {
  3159.             strcpy(Config->SerialConfig->SerialDevice,Args[ARG_OPENDEVICE_NAME]);
  3160.  
  3161.             ConfigChanged = TRUE;
  3162.         }
  3163.  
  3164.         if(Args[ARG_OPENDEVICE_UNIT])
  3165.         {
  3166.             Config->SerialConfig->UnitNumber = *(LONG *)Args[ARG_OPENDEVICE_UNIT];
  3167.  
  3168.             ConfigChanged = TRUE;
  3169.         }
  3170.  
  3171.         BlockWindows();
  3172.  
  3173.         ReopenSerial();
  3174.  
  3175.         ReleaseWindows();
  3176.  
  3177.         return(CreateArgstring(Result,strlen(Result)));
  3178.     }
  3179. }
  3180.  
  3181. STRPTR
  3182. RexxParity(struct RexxPkt *Pkt)
  3183. {
  3184.     enum    {    ARG_PARITY_EVEN,ARG_PARITY_ODD,ARG_PARITY_NONE,ARG_PARITY_MARK,ARG_PARITY_SPACE };
  3185.  
  3186.     LONG OldMode;
  3187.     LONG Mode;
  3188.  
  3189.     if(Args[ARG_PARITY_EVEN])
  3190.         Mode = PARITY_EVEN;
  3191.  
  3192.     if(Args[ARG_PARITY_ODD])
  3193.         Mode = PARITY_ODD;
  3194.  
  3195.     if(Args[ARG_PARITY_NONE])
  3196.         Mode = PARITY_NONE;
  3197.  
  3198.     if(Args[ARG_PARITY_MARK])
  3199.         Mode = PARITY_MARK;
  3200.  
  3201.     if(Args[ARG_PARITY_SPACE])
  3202.         Mode = PARITY_SPACE;
  3203.  
  3204.     OldMode = Config->SerialConfig->Parity;
  3205.  
  3206.     if(Config->SerialConfig->Parity != Mode)
  3207.     {
  3208.         Config->SerialConfig->Parity = Mode;
  3209.  
  3210.         UpdateRequired = TRUE;
  3211.  
  3212.         ConfigChanged = TRUE;
  3213.     }
  3214.  
  3215.     return(CreateArgstring(ParityMappings[OldMode],strlen(ParityMappings[OldMode])));
  3216. }
  3217.  
  3218. STRPTR
  3219. RexxPasteClip(struct RexxPkt *Pkt)
  3220. {
  3221.     enum    {    ARG_PASTECLIP_UNIT };
  3222.  
  3223.     struct DataMsg *Msg;
  3224.     LONG Unit;
  3225.  
  3226.     if(Args[ARG_PASTECLIP_UNIT])
  3227.         Unit = *(LONG *)Args[ARG_PASTECLIP_UNIT];
  3228.     else
  3229.         Unit = Config->ClipConfig->ClipboardUnit;
  3230.  
  3231.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3232.     {
  3233.         Msg->Type = DATAMSGTYPE_WRITECLIP;
  3234.         Msg->Size = Unit;
  3235.  
  3236.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3237.     }
  3238.     else
  3239.     {
  3240.         ResultCode[0] = RC_ERROR;
  3241.         ResultCode[1] = ERROR_NO_FREE_STORE;
  3242.     }
  3243.  
  3244.     return(NULL);
  3245. }
  3246.  
  3247. STRPTR
  3248. RexxProcessIO(struct RexxPkt *Pkt)
  3249. {
  3250.     enum    {    ARG_PROCESSIO_ON,ARG_PROCESSIO_OFF };
  3251.  
  3252.     BOOL OldState;
  3253.  
  3254.     OldState = ProcessIO;
  3255.  
  3256.     if(Args[ARG_PROCESSIO_ON])
  3257.         ProcessIO = TRUE;
  3258.  
  3259.     if(Args[ARG_PROCESSIO_OFF])
  3260.         ProcessIO = FALSE;
  3261.  
  3262.     if(OldState != ProcessIO)
  3263.     {
  3264.         if(ProcessIO)
  3265.             RestartSerial();
  3266.  
  3267.         UpdateSerialJob();
  3268.  
  3269.         if(!ProcessIO)
  3270.             ClearSerial();
  3271.     }
  3272.  
  3273.     return(CreateArgstring(BooleanMappings[OldState],strlen(BooleanMappings[OldState])));
  3274. }
  3275.  
  3276. STRPTR
  3277. RexxProtocol(struct RexxPkt *Pkt)
  3278. {
  3279.     enum    {    ARG_PROTOCOL_NONE,ARG_PROTOCOL_RTSCTS,ARG_PROTOCOL_RTSCTSDTR };
  3280.  
  3281.     LONG OldMode;
  3282.     LONG Mode;
  3283.  
  3284.     if(Args[ARG_PROTOCOL_NONE])
  3285.         Mode = HANDSHAKING_NONE;
  3286.  
  3287.     if(Args[ARG_PROTOCOL_RTSCTS])
  3288.         Mode = HANDSHAKING_RTSCTS;
  3289.  
  3290.     if(Args[ARG_PROTOCOL_RTSCTSDTR])
  3291.         Mode = HANDSHAKING_RTSCTS_DSR;
  3292.  
  3293.     OldMode = Config->SerialConfig->HandshakingProtocol;
  3294.  
  3295.     if(Config->SerialConfig->HandshakingProtocol != Mode)
  3296.     {
  3297.         Config->SerialConfig->HandshakingProtocol = Mode;
  3298.  
  3299.         UpdateRequired = TRUE;
  3300.  
  3301.         ConfigChanged = TRUE;
  3302.     }
  3303.  
  3304.     return(CreateArgstring(HandshakingMappings[OldMode],strlen(HandshakingMappings[OldMode])));
  3305. }
  3306.  
  3307. STRPTR
  3308. RexxPutClip(struct RexxPkt *Pkt)
  3309. {
  3310.     enum    {    ARG_PUTCLIP_UNIT,ARG_PUTCLIP_TEXT };
  3311.  
  3312.     struct IFFHandle *Handle;
  3313.     LONG Unit,Error;
  3314.  
  3315.     if(Args[ARG_PUTCLIP_UNIT])
  3316.         Unit = *(LONG *)Args[ARG_PUTCLIP_UNIT];
  3317.     else
  3318.         Unit = Config->ClipConfig->ClipboardUnit;
  3319.  
  3320.     if(Handle = OpenIFFClip(Unit,MODE_NEWFILE))
  3321.     {
  3322.         if(!(Error = PushChunk(Handle,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN)))
  3323.         {
  3324.             if(!(Error = PushChunk(Handle,0,ID_CHRS,IFFSIZE_UNKNOWN)))
  3325.             {
  3326.                 LONG Len = strlen(Args[ARG_PUTCLIP_TEXT]);
  3327.  
  3328.                 if(WriteChunkBytes(Handle,Args[ARG_PUTCLIP_TEXT],Len) == Len)
  3329.                     Error = PopChunk(Handle);
  3330.                 else
  3331.                     Error = IoErr();
  3332.             }
  3333.         }
  3334.  
  3335.         if(!Error)
  3336.             Error = PopChunk(Handle);
  3337.  
  3338.         CloseIFFClip(Handle);
  3339.     }
  3340.     else
  3341.         Error = IoErr();
  3342.  
  3343.     if(Error)
  3344.     {
  3345.         ResultCode[0] = RC_ERROR;
  3346.         ResultCode[1] = Error;
  3347.     }
  3348.  
  3349.     return(NULL);
  3350. }
  3351.  
  3352. STRPTR
  3353. RexxQuit(struct RexxPkt *Pkt)
  3354. {
  3355.     enum    {    ARG_QUIT_FORCE };
  3356.  
  3357.     struct DataMsg *Msg;
  3358.  
  3359.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3360.     {
  3361.         Pkt->RexxMsg->rm_Result1 = RC_WARN;
  3362.         Pkt->RexxMsg->rm_Result2 = 0;
  3363.  
  3364.         ReplyMsg((struct Message *)Pkt->RexxMsg);
  3365.  
  3366.         Pkt->RexxMsg = NULL;
  3367.  
  3368.         Msg->Type = DATAMSGTYPE_MENU;
  3369.         Msg->Size = MEN_QUIT;
  3370.  
  3371.         if(Args[ARG_QUIT_FORCE])
  3372.             Msg->Data = (APTR)SHIFT_KEY;
  3373.         else
  3374.             Msg->Data = NULL;
  3375.  
  3376.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3377.     }
  3378.     else
  3379.     {
  3380.         ResultCode[0] = RC_ERROR;
  3381.         ResultCode[1] = ERROR_NO_FREE_STORE;
  3382.     }
  3383.  
  3384.     return(NULL);
  3385. }
  3386.  
  3387. STRPTR
  3388. RexxRedial(struct RexxPkt *Pkt)
  3389. {
  3390.     struct DataMsg *Msg;
  3391.  
  3392.     if(Msg = (struct DataMsg *)CreateMsgItem(sizeof(struct DataMsg)))
  3393.     {
  3394.         Msg->Type = DATAMSGTYPE_REDIAL;
  3395.  
  3396.         PutMsgItem(SpecialQueue,(struct MsgItem *)Msg);
  3397.     }
  3398.     else
  3399.         ResultCode[0] = RC_WARN;
  3400.  
  3401.     return(NULL);
  3402. }
  3403.  
  3404. STRPTR
  3405. RexxRequestNotify(struct RexxPkt *Pkt)
  3406. {
  3407.     enum    {    ARG_REQUESTNOTIFY_TITLE,ARG_REQUESTNOTIFY_PROMPT };
  3408.  
  3409.     struct EasyStruct Easy;
  3410.  
  3411.     Easy.es_StructSize        = sizeof(struct EasyStruct);
  3412.     Easy.es_Flags            = NULL;
  3413.     Easy.es_TextFormat        = Args[ARG_REQUESTNOTIFY_PROMPT];
  3414.     Easy.es_GadgetFormat    = LocaleString(MSG_GLOBAL_CONTINUE_TXT);
  3415.  
  3416.     if(Args[ARG_REQUESTNOTIFY_TITLE])
  3417.         Easy.es_Title = Args[ARG_REQUESTNOTIFY_TITLE];
  3418.     else
  3419.         Easy.es_Title = LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  3420.  
  3421.     BlockWindows();
  3422.  
  3423.     EasyRequestArgs(Window,&Easy,NULL,NULL);
  3424.  
  3425.     ReleaseWindows();
  3426.  
  3427.     return(NULL);
  3428. }
  3429.  
  3430. STRPTR
  3431. RexxRequestNumber(struct RexxPkt *Pkt)
  3432. {
  3433.     enum    {    ARG_REQUESTNUMBER_DEFAULT,ARG_REQUESTNUMBER_PROMPT };
  3434.  
  3435.     UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  3436.  
  3437.     if(Args[ARG_REQUESTNUMBER_DEFAULT])
  3438.         LimitedSPrintf(sizeof(DummyBuffer),DummyBuffer,"%ld",*(LONG *)Args[ARG_REQUESTNUMBER_DEFAULT]);
  3439.     else
  3440.         DummyBuffer[0] = 0;
  3441.  
  3442.     BlockWindows();
  3443.  
  3444.     if(GetString(FALSE,FALSE,sizeof(DummyBuffer)-1,Args[ARG_REQUESTNUMBER_PROMPT],DummyBuffer))
  3445.     {
  3446.         STRPTR Index = DummyBuffer;
  3447.  
  3448.         while(*Index == ' ' || *Index == '\t')
  3449.             Index++;
  3450.  
  3451.         if(*Index)
  3452.         {
  3453.             LONG Value;
  3454.  
  3455.             if(StrToLong(DummyBuffer,&Value) == -1)
  3456.             {
  3457.                 ResultCode[0] = RC_ERROR;
  3458.                 ResultCode[1] = ERROR_BAD_NUMBER;
  3459.             }
  3460.             else
  3461.             {
  3462.                 ReleaseWindows();
  3463.  
  3464.                 LimitedSPrintf(sizeof(DummyBuffer),DummyBuffer,"%ld",Value);
  3465.  
  3466.                 return(CreateResult(DummyBuffer,ResultCode));
  3467.             }
  3468.         }
  3469.         else
  3470.             ResultCode[0] = RC_WARN;
  3471.     }
  3472.     else
  3473.         ResultCode[0] = RC_WARN;
  3474.  
  3475.     ReleaseWindows();
  3476.  
  3477.     return(NULL);
  3478. }
  3479.  
  3480. STRPTR
  3481. RexxRequestResponse(struct RexxPkt *Pkt)
  3482. {
  3483.     enum    {    ARG_REQUESTRESPONSE_TITLE,ARG_REQUESTRESPONSE_OPTIONS,
  3484.                 ARG_REQUESTRESPONSE_PROMPT
  3485.             };
  3486.  
  3487.     struct EasyStruct Easy;
  3488.     LONG Result;
  3489.  
  3490.     Easy.es_StructSize    = sizeof(struct EasyStruct);
  3491.     Easy.es_Flags        = NULL;
  3492.     Easy.es_TextFormat    = Args[ARG_REQUESTRESPONSE_PROMPT];
  3493.  
  3494.     if(Args[ARG_REQUESTRESPONSE_OPTIONS])
  3495.         Easy.es_GadgetFormat = Args[ARG_REQUESTRESPONSE_OPTIONS];
  3496.     else
  3497.         Easy.es_GadgetFormat = LocaleString(MSG_GLOBAL_YES_NO_TXT);
  3498.  
  3499.     if(Args[ARG_REQUESTRESPONSE_TITLE])
  3500.         Easy.es_Title = Args[ARG_REQUESTRESPONSE_TITLE];
  3501.     else
  3502.         Easy.es_Title = LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  3503.  
  3504.     BlockWindows();
  3505.  
  3506.     Result = EasyRequestArgs(Window,&Easy,NULL,NULL);
  3507.  
  3508.     ReleaseWindows();
  3509.  
  3510.     if(Result)
  3511.     {
  3512.         UBYTE DummyBuffer[20];
  3513.  
  3514.         LimitedSPrintf(sizeof(DummyBuffer),DummyBuffer,"%ld",Result);
  3515.  
  3516.         return(CreateResult(DummyBuffer,ResultCode));
  3517.     }
  3518.     else
  3519.     {
  3520.         ResultCode[0] = RC_WARN;
  3521.  
  3522.         return(NULL);
  3523.     }
  3524. }
  3525.  
  3526. STRPTR
  3527. RexxRequestString(struct RexxPkt *Pkt)
  3528. {
  3529.     enum    {    ARG_REQUESTSTRING_SECRET,ARG_REQUESTSTRING_DEFAULT,ARG_REQUESTSTRING_PROMPT };
  3530.  
  3531.     UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
  3532.  
  3533.     if(Args[ARG_REQUESTSTRING_DEFAULT])
  3534.         strcpy(DummyBuffer,Args[ARG_REQUESTSTRING_DEFAULT]);
  3535.     else
  3536.         DummyBuffer[0] = 0;
  3537.  
  3538.     BlockWindows();
  3539.  
  3540.     if(GetString(FALSE,Args[ARG_REQUESTSTRING_SECRET] != NULL,sizeof(DummyBuffer) - 1,Args[ARG_REQUESTSTRING_PROMPT],DummyBuffer))
  3541.     {
  3542.         ReleaseWindows();
  3543.  
  3544.         return(CreateResult(DummyBuffer,ResultCode));
  3545.     }
  3546.     else
  3547.         ResultCode[0] = RC_WARN;
  3548.  
  3549.     ReleaseWindows();
  3550.  
  3551.     return(NULL);
  3552. }
  3553.  
  3554. STRPTR
  3555. RexxReset(struct RexxPkt *Pkt)
  3556. {
  3557.     enum    {    ARG_CLEAR,ARG_STYLE,ARG_TEXT,ARG_TIMER };
  3558.  
  3559.     if(Args[ARG_CLEAR])
  3560.         RexxResetScreen(Pkt);
  3561.  
  3562.     if(Args[ARG_STYLE])
  3563.         RexxResetStyles(Pkt);
  3564.  
  3565.     if(Args[ARG_TEXT])
  3566.         RexxResetText(Pkt);
  3567.  
  3568.     if(Args[ARG_TIMER])
  3569.         RexxResetTimer(Pkt);
  3570.  
  3571.     return(NULL);
  3572. }
  3573.  
  3574. STRPTR
  3575. RexxResetScreen(struct RexxPkt *UnusedPkt)
  3576. {
  3577.     ConResetTerminal();
  3578.  
  3579.     return(NULL);
  3580. }
  3581.  
  3582. STRPTR
  3583. RexxResetStyles(struct RexxPkt *UnusedPkt)
  3584. {
  3585.     ConResetStyles();
  3586.  
  3587.     return(NULL);
  3588. }
  3589.  
  3590. STRPTR
  3591. RexxResetText(struct RexxPkt *UnusedPkt)
  3592. {
  3593.     ConResetFont();
  3594.  
  3595.     return(NULL);
  3596. }
  3597.  
  3598. STRPTR
  3599. RexxResetTimer(struct RexxPkt *UnusedPkt)
  3600. {
  3601.     Forbid();
  3602.  
  3603.     if(StatusProcess)
  3604.         Signal((struct Task *)StatusProcess,SIG_RESETTIME);
  3605.  
  3606.     Permit();
  3607.  
  3608.     return(NULL);
  3609. }
  3610.  
  3611. STRPTR
  3612. RexxSave(struct RexxPkt *Pkt)
  3613. {
  3614.     enum    {    ARG_SAVE_FROM };
  3615.  
  3616.     Args[1] = Args[ARG_SAVE_FROM];
  3617.     Args[0] = NULL;
  3618.  
  3619.     return(RexxSaveAs(Pkt));
  3620. }
  3621.  
  3622. STRPTR
  3623. RexxSend(struct RexxPkt *Pkt)
  3624. {
  3625.     enum    {    ARG_SEND_NOECHO,ARG_SEND_LOCAL,ARG_SEND_LITERAL,ARG_SEND_BYTE,ARG_SEND_TEXT };
  3626.  
  3627.     if(Args[ARG_SEND_LOCAL])
  3628.     {
  3629.         if(!Args[ARG_SEND_NOECHO])
  3630.         {
  3631.             if(Marking)
  3632.                 WindowMarkerStop();
  3633.  
  3634.             if(Args[ARG_SEND_TEXT])
  3635.             {
  3636.                 if(Args[ARG_SEND_LITERAL])
  3637.                     ConProcess(Args[ARG_SEND_TEXT],strlen(Args[ARG_SEND_TEXT]));
  3638.                 else
  3639.                     ConsoleCommand(Args[ARG_SEND_TEXT]);
  3640.             }
  3641.             else
  3642.             {
  3643.                 UBYTE Byte = *(LONG *)Args[ARG_SEND_BYTE];
  3644.  
  3645.                 ConProcess(&Byte,1);
  3646.             }
  3647.         }
  3648.     }
  3649.     else
  3650.     {
  3651.         BOOL OldSettings;
  3652.  
  3653.         OldSettings = SetConsoleQuiet((BOOL)(Args[ARG_SEND_NOECHO] != NULL));
  3654.  
  3655.         if(Args[ARG_SEND_TEXT])
  3656.         {
  3657.             if(Args[ARG_SEND_LITERAL])
  3658.                 SerWrite(Args[ARG_SEND_TEXT],strlen(Args[ARG_SEND_TEXT]));
  3659.             else
  3660.                 SerialCommand(Args[ARG_SEND_TEXT]);
  3661.         }
  3662.         else
  3663.         {
  3664.             UBYTE Byte = *(LONG *)Args[ARG_SEND_BYTE];
  3665.  
  3666.             SerWrite(&Byte,1);
  3667.         }
  3668.  
  3669.         SetConsoleQuiet(OldSettings);
  3670.     }
  3671.  
  3672.     return(NULL);
  3673. }
  3674.  
  3675. STRPTR
  3676. RexxSendBreak(struct RexxPkt *Pkt)
  3677. {
  3678.     if(WriteRequest)
  3679.         SendBreak();
  3680.     else
  3681.         ResultCode[0] = RC_WARN;
  3682.  
  3683.     return(NULL);
  3684. }
  3685.  
  3686. STRPTR
  3687. RexxSpeak(struct RexxPkt *Pkt)
  3688. {
  3689.     enum    {    ARG_SPEAK_TEXT };
  3690.  
  3691.     if(SpeechConfig.Enabled && English)
  3692.         Say(Args[ARG_SPEAK_TEXT]);
  3693.     else
  3694.         ResultCode[0] = RC_WARN;
  3695.  
  3696.     return(NULL);
  3697. }
  3698.  
  3699. STRPTR
  3700. RexxStopBits(struct RexxPkt *Pkt)
  3701. {
  3702.     enum    {    ARG_STOPBITS_0,ARG_STOPBITS_1 };
  3703.  
  3704.     LONG Bits;
  3705.     UBYTE Number[10];
  3706.  
  3707.     LimitedSPrintf(sizeof(Number),Number,"%ld",Config->SerialConfig->StopBits);
  3708.  
  3709.     if(Args[ARG_STOPBITS_0])
  3710.         Bits = 0;
  3711.  
  3712.     if(Args[ARG_STOPBITS_1])
  3713.         Bits = 1;
  3714.  
  3715.     if(Config->SerialConfig->StopBits != Bits)
  3716.     {
  3717.         Config->SerialConfig->StopBits = Bits;
  3718.  
  3719.         UpdateRequired = TRUE;
  3720.  
  3721.         ConfigChanged = TRUE;
  3722.     }
  3723.  
  3724.     return(CreateArgstring(Number,strlen(Number)));
  3725. }
  3726.  
  3727. STRPTR
  3728. RexxTextBuffer(struct RexxPkt *Pkt)
  3729. {
  3730.     enum    {    ARG_TEXTBUFFER_LOCK,ARG_TEXTBUFFER_UNLOCK };
  3731.  
  3732.     Forbid();
  3733.  
  3734.     if(Args[ARG_TEXTBUFFER_LOCK])
  3735.         BufferFrozen = TRUE;
  3736.  
  3737.     if(Args[ARG_TEXTBUFFER_UNLOCK])
  3738.         BufferFrozen = FALSE;
  3739.  
  3740.     ConOutputUpdate();
  3741.  
  3742.     Permit();
  3743.  
  3744.     CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  3745.  
  3746.     return(NULL);
  3747. }
  3748.  
  3749. STRPTR
  3750. RexxTimeout(struct RexxPkt *Pkt)
  3751. {
  3752.     enum    {    ARG_TIMEOUT_SECONDS,ARG_TIMEOUT_OFF };
  3753.  
  3754.     if(Args[ARG_TIMEOUT_OFF])
  3755.         RexxTimeoutVal = 0;
  3756.     else
  3757.         RexxTimeoutVal = *(LONG *)Args[ARG_TIMEOUT_SECONDS];
  3758.  
  3759.     return(NULL);
  3760.  
  3761. }
  3762.  
  3763. STRPTR
  3764. RexxTrap(struct RexxPkt *Pkt)
  3765. {
  3766.     enum    {    ARG_TRAP_ON,ARG_TRAP_OFF };
  3767.  
  3768.     BOOL Enabled;
  3769.  
  3770.     if(Args[ARG_TRAP_ON])
  3771.         Enabled = TRUE;
  3772.  
  3773.     if(Args[ARG_TRAP_OFF])
  3774.         Enabled = FALSE;
  3775.  
  3776.     CheckItem(MEN_DISABLE_TRAPS,Enabled != TRUE);
  3777.  
  3778.     if(GenericListCount(GenericListTable[GLIST_TRAP]) != 0 && Enabled)
  3779.         WatchTraps = TRUE;
  3780.     else
  3781.         WatchTraps = FALSE;
  3782.  
  3783.     return(NULL);
  3784. }
  3785.  
  3786. STRPTR
  3787. RexxWindow(struct RexxPkt *Pkt)
  3788. {
  3789.     enum    {    ARG_WINDOW_NAMES,ARG_WINDOW_OPEN,ARG_WINDOW_CLOSE,ARG_WINDOW_ACTIVATE,
  3790.                 ARG_WINDOW_MIN,ARG_WINDOW_MAX,ARG_WINDOW_FRONT,ARG_WINDOW_BACK,
  3791.                 ARG_WINDOW_TOP,ARG_WINDOW_BOTTOM,ARG_WINDOW_UP,ARG_WINDOW_DOWN
  3792.             };
  3793.  
  3794.     STRPTR    *Names = (STRPTR *)Args[ARG_WINDOW_NAMES];
  3795.     LONG     Index;
  3796.  
  3797.     while(*Names)
  3798.     {
  3799.         if((Index = ToWindow(*Names++)) != -1)
  3800.         {
  3801.             if(Args[ARG_WINDOW_OPEN])
  3802.             {
  3803.                 Forbid();
  3804.  
  3805.                 switch(Index)
  3806.                 {
  3807.                     case WINDOWID_BUFFER:
  3808.  
  3809.                         LaunchBuffer();
  3810.                         break;
  3811.  
  3812.                     case WINDOWID_UPLOAD_QUEUE:
  3813.  
  3814.                         CreateQueueProcess();
  3815.  
  3816.                         break;
  3817.  
  3818.                     case WINDOWID_REVIEW:
  3819.  
  3820.                         if(!ReviewWindow)
  3821.                             CreateReview();
  3822.  
  3823.                         break;
  3824.  
  3825.                     case WINDOWID_PACKET:
  3826.  
  3827.                         if(!PacketWindow)
  3828.                             CreatePacketWindow();
  3829.  
  3830.                         break;
  3831.  
  3832.                     case WINDOWID_FASTMACROS:
  3833.  
  3834.                         if(!FastWindow)
  3835.                             OpenFastWindow();
  3836.  
  3837.                         break;
  3838.  
  3839.                     case WINDOWID_STATUS:
  3840.  
  3841.                         if(!InfoWindow)
  3842.                             OpenInfoWindow();
  3843.  
  3844.                         break;
  3845.  
  3846.                     case WINDOWID_MAIN:
  3847.  
  3848.                         if(!IconTerminated)
  3849.                             IconTerminated = TRUE;
  3850.  
  3851.                         break;
  3852.  
  3853.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  3854.  
  3855.                         if(Window)
  3856.                             OpenMatrixWindow(Window);
  3857.  
  3858.                         break;
  3859.                 }
  3860.  
  3861.                 Permit();
  3862.             }
  3863.  
  3864.             if(Args[ARG_WINDOW_CLOSE])
  3865.             {
  3866.                 Forbid();
  3867.  
  3868.                 switch(Index)
  3869.                 {
  3870.                     case WINDOWID_UPLOAD_QUEUE:
  3871.  
  3872.                         CloseQueueWindow();
  3873.                         break;
  3874.  
  3875.                     case WINDOWID_BUFFER:
  3876.  
  3877.                         TerminateBuffer();
  3878.                         break;
  3879.  
  3880.                     case WINDOWID_REVIEW:
  3881.  
  3882.                         if(ReviewWindow)
  3883.                             DeleteReview();
  3884.  
  3885.                         break;
  3886.  
  3887.                     case WINDOWID_PACKET:
  3888.  
  3889.                         if(PacketWindow)
  3890.                             DeletePacketWindow(FALSE);
  3891.  
  3892.                         break;
  3893.  
  3894.                     case WINDOWID_FASTMACROS:
  3895.  
  3896.                         if(FastWindow)
  3897.                             CloseFastWindow();
  3898.  
  3899.                         break;
  3900.  
  3901.                     case WINDOWID_STATUS:
  3902.  
  3903.                         if(InfoWindow)
  3904.                             CloseInfoWindow();
  3905.  
  3906.                         break;
  3907.  
  3908.                     case WINDOWID_MAIN:
  3909.  
  3910.                         if(Window)
  3911.                             ActivateJob(MainJobQueue,IconifyJob);
  3912.  
  3913.                         break;
  3914.  
  3915.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  3916.  
  3917.                         CloseMatrixWindow();
  3918.                         break;
  3919.                 }
  3920.  
  3921.                 Permit();
  3922.             }
  3923.  
  3924.             if(Args[ARG_WINDOW_ACTIVATE])
  3925.             {
  3926.                 Forbid();
  3927.  
  3928.                 switch(Index)
  3929.                 {
  3930.                     case WINDOWID_UPLOAD_QUEUE:
  3931.  
  3932.                         CreateQueueProcess();
  3933.  
  3934.                         break;
  3935.  
  3936.                     case WINDOWID_BUFFER:
  3937.  
  3938.                         LaunchBuffer();
  3939.                         break;
  3940.  
  3941.                     case WINDOWID_REVIEW:
  3942.  
  3943.                         if(ReviewWindow)
  3944.                             BumpWindow(ReviewWindow);
  3945.  
  3946.                         break;
  3947.  
  3948.                     case WINDOWID_PACKET:
  3949.  
  3950.                         if(PacketWindow)
  3951.                             BumpWindow(PacketWindow);
  3952.  
  3953.                         break;
  3954.  
  3955.                     case WINDOWID_FASTMACROS:
  3956.  
  3957.                         if(FastWindow)
  3958.                             BumpWindow(FastWindow);
  3959.  
  3960.                         break;
  3961.  
  3962.                     case WINDOWID_STATUS:
  3963.  
  3964.                         if(InfoWindow)
  3965.                             BumpWindow(InfoWindow);
  3966.  
  3967.                         break;
  3968.  
  3969.                     case WINDOWID_MAIN:
  3970.  
  3971.                         if(Window)
  3972.                             BumpWindow(Window);
  3973.  
  3974.                         break;
  3975.  
  3976.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  3977.  
  3978.                         if(MatrixWindow)
  3979.                             BumpWindow(MatrixWindow);
  3980.  
  3981.                         break;
  3982.                 }
  3983.  
  3984.                 Permit();
  3985.             }
  3986.  
  3987.             if(Args[ARG_WINDOW_MIN])
  3988.             {
  3989.                 struct Window *SomeWindow = NULL;
  3990.  
  3991.                 Forbid();
  3992.  
  3993.                 switch(Index)
  3994.                 {
  3995.                     case WINDOWID_REVIEW:
  3996.  
  3997.                         SomeWindow = ReviewWindow;
  3998.                         break;
  3999.  
  4000.                     case WINDOWID_PACKET:
  4001.  
  4002.                         SomeWindow = PacketWindow;
  4003.                         break;
  4004.  
  4005.                     case WINDOWID_FASTMACROS:
  4006.  
  4007.                         SomeWindow = FastWindow;
  4008.                         break;
  4009.  
  4010.                     case WINDOWID_STATUS:
  4011.  
  4012.                         SomeWindow = InfoWindow;
  4013.                         break;
  4014.                 }
  4015.  
  4016.                 if(SomeWindow)
  4017.                     ChangeWindowBox(SomeWindow,SomeWindow->LeftEdge,SomeWindow->TopEdge,SomeWindow->MinWidth,SomeWindow->MinHeight);
  4018.  
  4019.                 Permit();
  4020.             }
  4021.  
  4022.             if(Args[ARG_WINDOW_MAX])
  4023.             {
  4024.                 struct Window *SomeWindow = NULL;
  4025.  
  4026.                 Forbid();
  4027.  
  4028.                 switch(Index)
  4029.                 {
  4030.                     case WINDOWID_REVIEW:
  4031.  
  4032.                         SomeWindow = ReviewWindow;
  4033.                         break;
  4034.  
  4035.                     case WINDOWID_PACKET:
  4036.  
  4037.                         SomeWindow = PacketWindow;
  4038.                         break;
  4039.  
  4040.                     case WINDOWID_FASTMACROS:
  4041.  
  4042.                         SomeWindow = FastWindow;
  4043.                         break;
  4044.  
  4045.                     case WINDOWID_STATUS:
  4046.  
  4047.                         SomeWindow = InfoWindow;
  4048.                         break;
  4049.                 }
  4050.  
  4051.                 if(SomeWindow)
  4052.                     ChangeWindowBox(SomeWindow,0,0,SomeWindow->MaxWidth,SomeWindow->MaxHeight);
  4053.  
  4054.                 Permit();
  4055.             }
  4056.  
  4057.             if(Args[ARG_WINDOW_FRONT])
  4058.             {
  4059.                 Forbid();
  4060.  
  4061.                 switch(Index)
  4062.                 {
  4063.                     case WINDOWID_UPLOAD_QUEUE:
  4064.  
  4065.                         CreateQueueProcess();
  4066.  
  4067.                         break;
  4068.  
  4069.                     case WINDOWID_BUFFER:
  4070.  
  4071.                         LaunchBuffer();
  4072.                         break;
  4073.  
  4074.                     case WINDOWID_REVIEW:
  4075.  
  4076.                         if(ReviewWindow)
  4077.                             WindowToFront(ReviewWindow);
  4078.  
  4079.                         break;
  4080.  
  4081.                     case WINDOWID_PACKET:
  4082.  
  4083.                         if(PacketWindow)
  4084.                             WindowToFront(PacketWindow);
  4085.  
  4086.                         break;
  4087.  
  4088.                     case WINDOWID_FASTMACROS:
  4089.  
  4090.                         if(FastWindow)
  4091.                             WindowToFront(FastWindow);
  4092.  
  4093.                         break;
  4094.  
  4095.                     case WINDOWID_STATUS:
  4096.  
  4097.                         if(InfoWindow)
  4098.                             WindowToFront(InfoWindow);
  4099.  
  4100.                         break;
  4101.  
  4102.                     case WINDOWID_MAIN:
  4103.  
  4104.                         if(Window)
  4105.                             WindowToFront(Window);
  4106.  
  4107.                         break;
  4108.  
  4109.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  4110.  
  4111.                         if(MatrixWindow)
  4112.                             WindowToFront(MatrixWindow);
  4113.  
  4114.                         break;
  4115.                 }
  4116.  
  4117.                 Permit();
  4118.             }
  4119.  
  4120.             if(Args[ARG_WINDOW_BACK])
  4121.             {
  4122.                 Forbid();
  4123.  
  4124.                 switch(Index)
  4125.                 {
  4126.                     case WINDOWID_REVIEW:
  4127.  
  4128.                         if(ReviewWindow)
  4129.                             WindowToBack(ReviewWindow);
  4130.  
  4131.                         break;
  4132.  
  4133.                     case WINDOWID_PACKET:
  4134.  
  4135.                         if(PacketWindow)
  4136.                             WindowToBack(PacketWindow);
  4137.  
  4138.                         break;
  4139.  
  4140.                     case WINDOWID_FASTMACROS:
  4141.  
  4142.                         if(FastWindow)
  4143.                             WindowToBack(FastWindow);
  4144.  
  4145.                         break;
  4146.  
  4147.                     case WINDOWID_STATUS:
  4148.  
  4149.                         if(InfoWindow)
  4150.                             WindowToBack(InfoWindow);
  4151.  
  4152.                         break;
  4153.  
  4154.                     case WINDOWID_MAIN:
  4155.  
  4156.                         if(Window)
  4157.                             WindowToBack(Window);
  4158.  
  4159.                         break;
  4160.  
  4161.                     case WINDOWID_SINGLE_CHAR_ENTRY:
  4162.  
  4163.                         if(MatrixWindow)
  4164.                             WindowToBack(MatrixWindow);
  4165.  
  4166.                         break;
  4167.                 }
  4168.  
  4169.                 Permit();
  4170.             }
  4171.  
  4172.             Forbid();
  4173.  
  4174.             if(Index == WINDOW_REVIEW && ReviewWindow)
  4175.             {
  4176.                 if(Args[ARG_WINDOW_TOP])
  4177.                     MoveReview(REVIEW_MOVE_TOP);
  4178.  
  4179.                 if(Args[ARG_WINDOW_BOTTOM])
  4180.                     MoveReview(REVIEW_MOVE_BOTTOM);
  4181.  
  4182.                 if(Args[ARG_WINDOW_UP])
  4183.                     MoveReview(REVIEW_MOVE_UP);
  4184.  
  4185.                 if(Args[ARG_WINDOW_DOWN])
  4186.                     MoveReview(REVIEW_MOVE_DOWN);
  4187.             }
  4188.  
  4189.             Permit();
  4190.         }
  4191.     }
  4192.  
  4193.     return(NULL);
  4194. }
  4195.  
  4196. STATIC VOID
  4197. RexxLaunchCleanup(LaunchMsg *Startup)
  4198. {
  4199.     struct RexxPkt *Pkt = Startup->RexxPkt;
  4200.  
  4201.     ResultCode[0] = Startup->Result;
  4202.     ResultCode[1] = Startup->Result2;
  4203.  
  4204.     RexxPktCleanup(Pkt,NULL);
  4205. }
  4206.  
  4207. STRPTR
  4208. RexxRX(struct RexxPkt *Pkt)
  4209. {
  4210.     enum    {    ARG_RX_CONSOLE,ARG_RX_ASYNC,ARG_RX_COMMAND };
  4211.  
  4212.     LaunchMsg    *Startup;
  4213.     BOOL         Eaten;
  4214.  
  4215.     if(!(Startup = CreateRexxCmdLaunchMsg(Args[ARG_RX_COMMAND],Pkt,Args[ARG_RX_ASYNC] ? NULL : RexxLaunchCleanup)))
  4216.     {
  4217.         ResultCode[0] = RC_ERROR;
  4218.         ResultCode[1] = ERR10_013;
  4219.  
  4220.         RexxPktCleanup(Pkt,NULL);
  4221.  
  4222.         return(NULL);
  4223.     }
  4224.  
  4225.     if(Args[ARG_RX_ASYNC])
  4226.     {
  4227.         RexxPktCleanup(Pkt,NULL);
  4228.  
  4229.         Eaten = TRUE;
  4230.     }
  4231.     else
  4232.         Eaten = FALSE;
  4233.  
  4234.     if(LaunchSomething(Args[ARG_RX_CONSOLE],!Eaten,Startup))
  4235.     {
  4236.         ResultCode[0] = RC_ERROR;
  4237.         ResultCode[1] = IoErr();
  4238.     }
  4239.     else
  4240.     {
  4241.         if(Eaten)
  4242.             DeleteLaunchMsg(Startup);
  4243.     }
  4244.  
  4245.     if(!Eaten)
  4246.         RexxPktCleanup(Pkt,NULL);
  4247.  
  4248.     return(NULL);
  4249. }
  4250.  
  4251. STRPTR
  4252. RexxExecTool(struct RexxPkt *Pkt)
  4253. {
  4254.     enum    {    ARG_EXECTOOL_CONSOLE,ARG_EXECTOOL_ASYNC,ARG_EXECTOOL_PORT,ARG_EXECTOOL_COMMAND };
  4255.  
  4256.     UBYTE         CommandName[MAX_FILENAME_LENGTH];
  4257.     UBYTE         CommandArgs[MAX_FILENAME_LENGTH];
  4258.     STRPTR         Index = Args[ARG_EXECTOOL_COMMAND];
  4259.     LONG         i;
  4260.     BOOL         Eaten;
  4261.     LaunchMsg    *Startup;
  4262.  
  4263.     while(*Index == ' ' || *Index == '\t')
  4264.         Index++;
  4265.  
  4266.     for(i = 0 ; Index[i] != ' ' && Index[i] != '\t' ; i++)
  4267.         CommandName[i] = Index[i];
  4268.  
  4269.     CommandName[i] = 0;
  4270.  
  4271.     Index += i;
  4272.  
  4273.     while(*Index == ' ' || *Index == '\t')
  4274.         Index++;
  4275.  
  4276.     if(Args[ARG_EXECTOOL_PORT])
  4277.         LimitedSPrintf(sizeof(CommandArgs),CommandArgs,"%s %s\n",Index,RexxPortName);
  4278.     else
  4279.         LimitedSPrintf(sizeof(CommandArgs),CommandArgs,"%s\n",Index);
  4280.  
  4281.     LimitedStrcat(sizeof(CommandName),CommandName," ");
  4282.     LimitedStrcat(sizeof(CommandName),CommandName,CommandArgs);
  4283.  
  4284.     if(!(Startup = CreateProgramLaunchMsg(CommandName,NULL)))
  4285.     {
  4286.         ResultCode[0] = RC_ERROR;
  4287.         ResultCode[1] = ERR10_013;
  4288.  
  4289.         RexxPktCleanup(Pkt,NULL);
  4290.  
  4291.         return(NULL);
  4292.     }
  4293.  
  4294.     if(Args[ARG_EXECTOOL_ASYNC])
  4295.     {
  4296.         RexxPktCleanup(Pkt,NULL);
  4297.  
  4298.         Eaten = TRUE;
  4299.     }
  4300.     else
  4301.         Eaten = FALSE;
  4302.  
  4303.     if(LaunchSomething(Args[ARG_EXECTOOL_CONSOLE],FALSE,Startup))
  4304.     {
  4305.         if(!Eaten)
  4306.         {
  4307.             ResultCode[0] = RC_ERROR;
  4308.             ResultCode[1] = IoErr();
  4309.         }
  4310.     }
  4311.     else
  4312.         DeleteLaunchMsg(Startup);
  4313.  
  4314.     if(!Eaten)
  4315.         RexxPktCleanup(Pkt,NULL);
  4316.  
  4317.     return(NULL);
  4318. }
  4319.  
  4320. STRPTR
  4321. RexxRead(struct RexxPkt *Pkt)
  4322. {
  4323.     enum    {    ARG_READ_NUM,ARG_READ_CR,ARG_READ_NOECHO,ARG_READ_VERBATIM,
  4324.                 ARG_TIMEOUT,ARG_TERMINATOR,ARG_READ_PROMPT
  4325.             };
  4326.  
  4327.     LONG MaxBytesToRead;
  4328.     LONG BytesRead;
  4329.     ULONG Signals;
  4330.     STRPTR Buffer;
  4331.     STRPTR Result;
  4332.     LONG Timeout;
  4333.     BOOL Done;
  4334.     BOOL Echo;
  4335.     WORD Terminator;
  4336.  
  4337.     if(!ReadRequest || !WriteRequest)
  4338.     {
  4339.         ResultCode[0] = RC_WARN;
  4340.  
  4341.         return(NULL);
  4342.     }
  4343.  
  4344.     if(Args[ARG_READ_NUM])
  4345.     {
  4346.         MaxBytesToRead = *(LONG *)Args[ARG_READ_NUM] + 1;
  4347.  
  4348.         if(MaxBytesToRead < 1)
  4349.         {
  4350.             ResultCode[0] = RC_ERROR;
  4351.             ResultCode[1] = ERROR_BAD_NUMBER;
  4352.  
  4353.             return(NULL);
  4354.         }
  4355.  
  4356.         if(MaxBytesToRead > MAX_RESULT_LEN + 1)
  4357.             MaxBytesToRead = MAX_RESULT_LEN + 1;
  4358.     }
  4359.     else
  4360.         MaxBytesToRead = MAX_RESULT_LEN + 1;
  4361.  
  4362.     if(!(Buffer = (STRPTR)AllocVecPooled(MaxBytesToRead,MEMF_ANY)))
  4363.     {
  4364.         ResultCode[0] = RC_ERROR;
  4365.         ResultCode[1] = ERROR_NO_FREE_STORE;
  4366.  
  4367.         return(NULL);
  4368.     }
  4369.  
  4370.     if(Args[ARG_READ_PROMPT])
  4371.         SerialCommand(Args[ARG_READ_PROMPT]);
  4372.  
  4373.     if(Args[ARG_READ_NOECHO])
  4374.         Echo = FALSE;
  4375.     else
  4376.         Echo = TRUE;
  4377.  
  4378.     if(Args[ARG_TIMEOUT])
  4379.         Timeout = *(LONG *)Args[ARG_TIMEOUT];
  4380.     else
  4381.         Timeout = RexxTimeoutVal;
  4382.  
  4383.     Terminator = -1;
  4384.  
  4385.     if(Args[ARG_TERMINATOR])
  4386.     {
  4387.         UBYTE LocalBuffer[256];
  4388.  
  4389.         if(TranslateString(Args[ARG_TERMINATOR],LocalBuffer) > 0)
  4390.             Terminator = LocalBuffer[0];
  4391.     }
  4392.  
  4393.     if(Timeout)
  4394.         StartTime(Timeout,0);
  4395.  
  4396.     Done = FALSE;
  4397.     BytesRead = 0;
  4398.  
  4399.     if(Args[ARG_READ_VERBATIM] || !ReceiveTable)
  4400.     {
  4401.         do
  4402.         {
  4403.             Signals = (*SerialWaitForData)(SIG_WINDOW | SIG_BREAK | SIG_TIMER);
  4404.  
  4405.             if(Signals & SIG_WINDOW)
  4406.                 while(RunJob(WindowJob));
  4407.  
  4408.             if(Signals & SIG_SERIAL)
  4409.             {
  4410.                 ULONG Length;
  4411.  
  4412.                 if(Length = (*SerialGetWaiting)())
  4413.                 {
  4414.                     if(Length > SerialBufferSize / 2)
  4415.                         Length = SerialBufferSize / 2;
  4416.  
  4417.                     if(Length > Config->SerialConfig->Quantum)
  4418.                         Length = Config->SerialConfig->Quantum;
  4419.  
  4420.                     if(Length = (*SerialRead)(ReadBuffer,Length))
  4421.                     {
  4422.                         BytesIn += Length;
  4423.  
  4424.                         if(Translate_CR_LF)
  4425.                             Length = (*Translate_CR_LF)(ReadBuffer,Length);
  4426.  
  4427.                         if(Length)
  4428.                         {
  4429.                             UBYTE *BufferPtr,c;
  4430.  
  4431.                             BufferPtr = ReadBuffer;
  4432.  
  4433.                             while(!Done && Length > 0)
  4434.                             {
  4435.                                 Length--;
  4436.  
  4437.                                 c = *BufferPtr++;
  4438.  
  4439.                                 if(c == Terminator)
  4440.                                 {
  4441.                                     if(Echo)
  4442.                                         ConProcess(&c,1);
  4443.  
  4444.                                     Done = TRUE;
  4445.                                     break;
  4446.                                 }
  4447.  
  4448.                                 switch(c)
  4449.                                 {
  4450.                                     case '\n':
  4451.  
  4452.                                         if(Echo)
  4453.                                             ConProcess(&c,1);
  4454.  
  4455.                                         break;
  4456.  
  4457.                                     case '\r':
  4458.  
  4459.                                         if(Args[ARG_READ_CR])
  4460.                                             Done = TRUE;
  4461.  
  4462.                                         if(Echo)
  4463.                                             ConProcess(&c,1);
  4464.  
  4465.                                         break;
  4466.  
  4467.                                     case '\b':
  4468.  
  4469.                                         if(BytesRead > 0)
  4470.                                         {
  4471.                                             BytesRead--;
  4472.  
  4473.                                             if(Echo)
  4474.                                                 ConProcess(&c,1);
  4475.                                         }
  4476.  
  4477.                                         break;
  4478.  
  4479.                                     case CONTROL_('X'):
  4480.  
  4481.                                         if(Echo)
  4482.                                         {
  4483.                                             while(BytesRead > 0)
  4484.                                             {
  4485.                                                 BytesRead--;
  4486.  
  4487.                                                 ConProcess("\b",1);
  4488.                                             }
  4489.                                         }
  4490.                                         else
  4491.                                             BytesRead = 0;
  4492.  
  4493.                                         break;
  4494.  
  4495.                                     default:
  4496.  
  4497.                                         if(BytesRead < MaxBytesToRead && ((c >= ' ' && c < 127) || c >= 160 || Config->TerminalConfig->FontMode == FONT_IBM))
  4498.                                         {
  4499.                                             Buffer[BytesRead++] = c;
  4500.  
  4501.                                             if(Echo)
  4502.                                                 ConProcess(&c,1);
  4503.                                         }
  4504.  
  4505.                                         break;
  4506.                                 }
  4507.                             }
  4508.                         }
  4509.                     }
  4510.                 }
  4511.             }
  4512.  
  4513.             if(Signals & (SIG_BREAK | SIG_TIMER))
  4514.             {
  4515.                 ResultCode[0] = RC_WARN;
  4516.  
  4517.                 Done = TRUE;
  4518.             }
  4519.         }
  4520.         while(!Done);
  4521.     }
  4522.     else
  4523.     {
  4524.         do
  4525.         {
  4526.             Signals = (*SerialWaitForData)(SIG_WINDOW | SIG_BREAK | SIG_TIMER);
  4527.  
  4528.             if(Signals & SIG_WINDOW)
  4529.                 while(RunJob(WindowJob));
  4530.  
  4531.             if(Signals & SIG_SERIAL)
  4532.             {
  4533.                 ULONG Length;
  4534.  
  4535.                 if(Length = (*SerialGetWaiting)())
  4536.                 {
  4537.                     if(Length > SerialBufferSize / 2)
  4538.                         Length = SerialBufferSize / 2;
  4539.  
  4540.                     if(Length > Config->SerialConfig->Quantum)
  4541.                         Length = Config->SerialConfig->Quantum;
  4542.  
  4543.                     if(Length = (*SerialRead)(ReadBuffer,Length))
  4544.                     {
  4545.                         BytesIn += Length;
  4546.  
  4547.                         if(Translate_CR_LF)
  4548.                             Length = (*Translate_CR_LF)(ReadBuffer,Length);
  4549.  
  4550.                         if(Length)
  4551.                         {
  4552.                             struct TranslationHandle Handle;
  4553.                             UBYTE c;
  4554.  
  4555.                             TranslateSetup(&Handle,ReadBuffer,Length,&c,1,ReceiveTable);
  4556.  
  4557.                             while(!Done && TranslateBuffer(&Handle))
  4558.                             {
  4559.                                 if(c == Terminator)
  4560.                                 {
  4561.                                     if(Echo)
  4562.                                         ConProcess(&c,1);
  4563.  
  4564.                                     Done = TRUE;
  4565.                                     break;
  4566.                                 }
  4567.  
  4568.                                 switch(c)
  4569.                                 {
  4570.                                     case '\n':
  4571.  
  4572.                                         if(Echo)
  4573.                                             ConProcess(&c,1);
  4574.  
  4575.                                         break;
  4576.  
  4577.                                     case '\r':
  4578.  
  4579.                                         if(Args[ARG_READ_CR])
  4580.                                             Done = TRUE;
  4581.  
  4582.                                         if(Echo)
  4583.                                             ConProcess(&c,1);
  4584.  
  4585.                                         break;
  4586.  
  4587.                                     case '\b':
  4588.  
  4589.                                         if(BytesRead > 0)
  4590.                                         {
  4591.                                             BytesRead--;
  4592.  
  4593.                                             if(Echo)
  4594.                                                 ConProcess(&c,1);
  4595.                                         }
  4596.  
  4597.                                         break;
  4598.  
  4599.                                     case CONTROL_('X'):
  4600.  
  4601.                                         if(Echo)
  4602.                                         {
  4603.                                             while(BytesRead > 0)
  4604.                                             {
  4605.                                                 BytesRead--;
  4606.  
  4607.                                                 ConProcess("\b",1);
  4608.                                             }
  4609.                                         }
  4610.                                         else
  4611.                                             BytesRead = 0;
  4612.  
  4613.                                         break;
  4614.  
  4615.                                     default:
  4616.  
  4617.                                         if(BytesRead < MaxBytesToRead && ((c >= ' ' && c < 127) || c >= 160 || Config->TerminalConfig->FontMode == FONT_IBM))
  4618.                                         {
  4619.                                             Buffer[BytesRead++] = c;
  4620.  
  4621.                                             if(Echo)
  4622.                                                 ConProcess(&c,1);
  4623.                                         }
  4624.  
  4625.                                         break;
  4626.                                 }
  4627.                             }
  4628.                         }
  4629.                     }
  4630.                 }
  4631.             }
  4632.  
  4633.             if(Signals & (SIG_BREAK | SIG_TIMER))
  4634.             {
  4635.                 ResultCode[0] = RC_WARN;
  4636.  
  4637.                 Done = TRUE;
  4638.             }
  4639.         }
  4640.         while(!Done);
  4641.     }
  4642.  
  4643.     StopTime();
  4644.  
  4645.     if(BytesRead > 0)
  4646.     {
  4647.         Buffer[BytesRead] = 0;
  4648.  
  4649.         Result = CreateResult(Buffer,ResultCode);
  4650.     }
  4651.     else
  4652.     {
  4653.         ResultCode[0] = RC_WARN;
  4654.         Result = NULL;
  4655.     }
  4656.  
  4657.     FreeVecPooled(Buffer);
  4658.  
  4659.     return(Result);
  4660. }
  4661.